Skip to content

v1.0.0

Choose a tag to compare

@bfren bfren released this 27 Jan 20:10
· 361 commits to main since this release
91ff99e

v1.0.0 Release

Taken from the wiki homepage.

Monad Marvels

Wrap C# values and objects in a variety of monads:

  • Maybe<T> - no more null! Values can be Some<T> containing a value, or None
  • Result<T> - no more exceptions! Values can be Ok<T> containing the value of a successful operation, or Failure containing information about why the operation failed
  • Id<T> - no more primitive IDs! Various types are provided for ID as Guid, int / uint or long / ulong

Underlying all those types is IUnion<T> - the base interface that all the monads inherit from, containing one property: T Value. Also we have IEither<TLeft, TRight> which is the base interface for Maybe<T> and Result<T>: the 'left' value is the invalid / error value, and the 'right' value is the valid / success value.

This enables a functional style where pure functions can be joined / linked together to compose more complex functions, using extension methods like .Map() and .Bind().

Linq Loveliness

Where Maybe<T> and Result<T> really shine is when you get into Linq syntax, which enables a sequence of operations to be joined together - as soon as one fails the others are short-circuited, saving CPU cycles. For example:

from db in Db.ConnectAsync(...)
from query in BuildQuery(...)
from posts in db.QueryPosts<T>(query ...)
select posts;

Assuming those three functions all return Result<T> the Linq query gives you a Result<T> object where T is the type of whatever you select.

Check out the source code for more info - I will expand the wiki with more info as and when I have time.