示例#1
0
        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));
        }
示例#2
0
        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
                    );
        }
示例#3
0
        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
                    );
        }
示例#4
0
        public void Should_Create_Success()
        {
            var value = Failable.From(true);

            Assert.True(value.Succeeded);
        }
示例#5
0
        public void Should_Create_Failure()
        {
            var value = Failable.From(new Exception());

            Assert.True(value.Failed);
        }