Skip to content

cptjazz/Bebop.Monads

Repository files navigation

Bebop.Monads

This project provides the following monads:

  • Maybe
  • Try

This library is:

  • netstandard2.0
  • strong-name signed
  • CLS compliant

NuGet Build status Coverage Status

Maybe

This represents the Maybe (or Option) monad.

var m = Maybe.From("these pretzels are making me thirsty");
var n = Maybe.Nothing<int>(); 

var x = m.OrElse("yada yada yada"); // yields "these pretzels ..."
var y = n.OrElse(17); // yields 17

See full documentation for Maybe;

Try

This represents an exceptional monad that can be used to construct lazy chains of action and catch blocks.

var result = await Try
    .Do(() => "I will succeed.")
    .ThenAsync(async x => x + " Oh will you?")
    .Then(_ => throw new InvalidOperationException())
    .Catch<InvalidOperationException>(ex => 
    {
        Log.WriteError("Operation did not succeed");
        return "failed";
    });

See full documentation for Try;

Unit

This represents the functional unit type.

var u = default(Unit);

See full documentation for Unit;

About

Provides a C# implementation of the Maybe monad.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages