Example #1
0
        public void OrElse()
        {
            Result <int, Exception> res1 = new Ok <int, Exception>(1);

            Assert.Equal(1, res1.OrElse(x => new Ok <int, Exception>(2)).Unwrap());
            Assert.Equal(1, res1.OrElse(e => new Err <int, Exception>(new Exception("this is test."))).Unwrap());

            Result <int, Exception> res2 = new Err <int, Exception>(new Exception("this is test."));

            Assert.Equal(2, res2.OrElse(x => new Ok <int, Exception>(2)).Unwrap());
            Assert.Equal(typeof(Err <int, ArgumentException>), res2.OrElse(e => new Err <int, ArgumentException>(new ArgumentException())).GetType());
        }