private static Failable <T> Where <T>(T value, Func <T, bool> predicate, Exception error) { #pragma warning disable CS8604 if (predicate(value) is false) { return(Failable.FromException <T>(error)); } return(Failable.From(value)); }
public void Should_Run_Success_Given_A_Value() { var nothing = Nothing.Of(); var failable = nothing .Do(() => Failable.From("success")) .Match( success: (value) => Assert.True(true), // pass failure: (error) => throw error // fail ); }
public void Should_Run_Success_Given_A_Value() { Maybe <string> maybe = "value"; _ = maybe .ToFailable() .Pipe( Do <string>((value) => Failable.From(value)) ) .Match( success: (value) => Assert.True(true), // pass failure: (_) => throw new Exception("It should not run this block") // fail ); }
public void Should_Create_Success() { var value = Failable.From(true); Assert.True(value.Succeeded); }
public void Should_Create_Failure() { var value = Failable.From(new Exception()); Assert.True(value.Failed); }