Skip to content

pgeerkens/Monads

Repository files navigation

Monads

C# library of basic monads and accompanying demos from my presentation to CoderCamp Hamilton S16E03 on March 9, 2016. It is licensed under the MIT License and can be used under those terms.

  • Maybe<T> is implemented as a struct similar to Nullable<T>, but allowing any subclass of object as its basetype whether struct or class.

  • MaybeX<T> is also implemented as a struct, with an implicit cast to Maybe<T>, that is optimized for class basetypes, by not storing the HasValue property explicitly.

  • Reader<E,T> and State<S,T> are delegate implementations of these well-known monads.

  • IO<T> is also a elegate implementation, with many common Console I/O functions predefined.

All the monads above:

  • come with the methods Select(), SelectMany() and SelectMany(,) predefined to enable the LINQ Comprehension (or Query) syntax.

  • Have been fully annotated with CodeContracts to statically disprove the largest possible number of null references.

The slide presentation is available here as Mathless Monads in C#.

Enjoy!

Pieter Geerkens

About

C# library of basic monads (Maybe, Reader, State, IO) and accompanying demos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published