// Monad public static IMaybe <TResult> SelectMany <T, TResult>( this IMaybe <T> source, Func <T, IMaybe <TResult> > selector) { return(source.Accept( new SelectManyMaybeVisitor <T, TResult>(selector))); }
public void SimpleQueryExpressionWorks() { IMaybe <int> sut = new Just <int>(42); IMaybe <string> actual = from i in sut select i.ToString(); Assert.Equal( "42", actual.Accept(new FromMaybeVisitor <string>("nothing"))); }
public static T GetValueOrDefault <T>(this IMaybe <T> source, T defaultValue) { return(source.Accept(new FromMaybeVisitor <T>(defaultValue))); }
public static bool IsNothing <T>(this IMaybe <T> source) { return(source.Accept(new IsNothingVisitor <T>())); }
// Monad public static IMaybe <T> Flatten <T>(this IMaybe <IMaybe <T> > source) { return(source.Accept(new FlattenMaybeVisitor <T>())); }
public static IChurchBoolean IsJust <T>(this IMaybe <T> m) { return(m.Accept(new IsJustMaybeVisitor <T>())); }