public static Fallible <TSource> PassBy <TSource, TOther>( this Fallible <TSource> @this, Fallible <TOther> other) { /* T4: NotNull(@this) */ return(@this.ZipWith(other, (arg, _) => arg)); }
public static Fallible <TResult> ContinueWith <TSource, TResult>( this Fallible <TSource> @this, Fallible <TResult> other) { /* T4: NotNull(@this) */ return(@this.Bind(_ => other)); }
/// <seealso cref="Fallible.Lift{T1, T2, T3, T4, T5, TResult}"/> public static Fallible <TResult> ZipWith <T1, T2, T3, T4, T5, TResult>( this Fallible <T1> @this, Fallible <T2> second, Fallible <T3> third, Fallible <T4> fourth, Fallible <T5> fifth, Func <T1, T2, T3, T4, T5, TResult> zipper) { /* T4: NotNull(@this) */ /* T4: NotNull(second) */ /* T4: NotNull(third) */ /* T4: NotNull(fourth) */ /* T4: NotNull(fifth) */ Require.NotNull(zipper, nameof(zipper)); // > return @this.Bind( // > arg1 => second.Bind( // > arg2 => third.Bind( // > arg3 => fourth.Bind( // > arg4 => fifth.Select( // > arg5 => zipper(arg1, arg2, arg3, arg4, arg5)))))); return(@this.Bind( arg1 => second.ZipWith( third, fourth, fifth, (arg2, arg3, arg4, arg5) => zipper(arg1, arg2, arg3, arg4, arg5)))); }
public static Fallible <TResult> ReplaceBy <TSource, TResult>( this Fallible <TSource> @this, TResult value) { /* T4: NotNull(@this) */ return(@this.Select(_ => value)); }
public static Fallible <TResult> InvokeWith <TSource, TResult>( this Func <TSource, Fallible <TResult> > @this, Fallible <TSource> value) { /* T4: NotNull(value) */ return(value.Bind(@this)); }
/// <seealso cref="Gather{TSource, TResult}" /> public static Fallible <TResult> Apply <TSource, TResult>( this Fallible <Func <TSource, TResult> > @this, Fallible <TSource> value) { /* T4: NotNull(value) */ return(value.Gather(@this)); }
public static void ValueOrThrow_ReturnsValue_IfSuccess() { var exp = new Obj(); var ok = Fallible.Of(exp); Assert.Same(exp, ok.ValueOrThrow()); }
public static void GetHashCode2() { var nok1 = Fallible.FromError(Error); var nok2 = Fallible.FromError(Error); Assert.Equal(nok1.GetHashCode(), nok2.GetHashCode()); }
public static void ToExceptionInfo2() { var nok = Fallible.FromError(Error); var result = nok.ToExceptionInfo(); Assert.Equal(Error, result); }
public static void cast2() { var nok = Fallible.FromError(Error); var result = (ExceptionDispatchInfo)nok; Assert.Equal(Error, result); }
public static void Equality3() { var ok = Fallible.Ok; var nok = Fallible.FromError(Error); Assert.True(nok != ok); }
public static void FromError1() { var nok = Fallible.FromError(Error); Assert.True(nok.IsError); Assert.False(nok.IsSuccess); }
public static void Deconstruct2() { var nok = Fallible.FromError(Error); var(succeed, err) = nok; Assert.False(succeed); Assert.Same(Error, err); }
/// <seealso cref="Apply{TSource, TResult}(Fallible{Func{TSource, TResult}}, Fallible{TSource})" /> public static Fallible <TResult> Gather <TSource, TResult>( this Fallible <TSource> @this, Fallible <Func <TSource, TResult> > applicative) { /* T4: NotNull(@this) */ /* T4: NotNull(applicative) */ return(applicative.Bind(func => @this.Select(func))); }
public static Fallible <IEnumerable <TSource> > Repeat <TSource>( Fallible <TSource> source, int count) { /* T4: NotNull(source) */ Require.Range(count >= 0, nameof(count)); return(source.Select(val => Enumerable.Repeat(val, count))); }
public static Fallible <TResult> Select <TSource, TResult>( this Fallible <TSource> @this, Func <TSource, TResult> selector) { /* T4: NotNull(@this) */ Require.NotNull(selector, nameof(selector)); return(@this.Bind(val => Fallible <TResult> .η(selector(val)))); }
// Select() with automatic resource management. public static Fallible <TResult> Using <TSource, TResult>( this Fallible <TSource> @this, Func <TSource, TResult> selector) where TSource : IDisposable { /* T4: NotNull(@this) */ Require.NotNull(selector, nameof(selector)); return(@this.Select(val => { using (val) { return selector(val); } })); }
// Bind() with automatic resource management. public static Fallible <TResult> Using <TSource, TResult>( this Fallible <TSource> @this, Func <TSource, Fallible <TResult> > binder) where TSource : IDisposable { /* T4: NotNull(@this) */ Require.NotNull(binder, nameof(binder)); return(@this.Bind(val => { using (val) { return binder(val); } })); }
public static void Deconstruct2() { var nok = Fallible <Obj> .FromError(Error); var(succeed, value, err) = nok; Assert.False(succeed); Assert.Same(Error, err); Assert.Null(value); }
public static void ValueOrElse_ReturnsValue_IfSuccess() { var exp = new Obj(); var ok = Fallible.Of(exp); var other = new Obj("other"); Assert.Same(exp, ok.ValueOrElse(other)); Assert.Same(exp, ok.ValueOrElse(() => other)); }
public static void ValueOrElse_ReturnsOther_IfError() { var nok = Fallible <Obj> .FromError(Error); var exp = new Obj(); Assert.Same(exp, nok.ValueOrElse(exp)); Assert.Same(exp, nok.ValueOrElse(() => exp)); }
public Fallible <TResult> ZipWith <TSecond, TResult>( Fallible <TSecond> second, Func <T, TSecond, TResult> zipper) { Require.NotNull(zipper, nameof(zipper)); return(IsError && second.IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(zipper(Value, second.Value))); }
public static void ThrowIfError2() { var nok = Fallible.FromError(Error); var ex = Record.Exception(() => nok.ThrowIfError()); Assert.NotNull(ex); Assert.IsType <SimpleException>(ex); Assert.Equal(ErrorMessage, ex.Message); }
public static void GetHashCode1() { var nok = Fallible.FromError(Error); Assert.Equal(nok.GetHashCode(), nok.GetHashCode()); var ok = Fallible.Ok; Assert.Equal(ok.GetHashCode(), ok.GetHashCode()); }
public static void Deconstruct1() { var exp = new Obj(); var ok = Fallible.Of(exp); var(succeed, value, err) = ok; Assert.True(succeed); Assert.Null(err); Assert.Same(exp, value); }
public static void Equals1() { var ok = Fallible.Ok; Assert.True(ok.Equals(ok)); var nok = Fallible.FromError(Error); Assert.True(nok.Equals(nok)); }
public static void ValueOrElse0() { var ok = Fallible.Of(new Obj()); Assert.Throws <ArgumentNullException>("valueFactory", () => ok.ValueOrElse((Func <Obj>)null)); var nok = Fallible <Obj> .FromError(Error); Assert.Throws <ArgumentNullException>("valueFactory", () => nok.ValueOrElse((Func <Obj>)null)); }
public static void Equals3() { var ok = Fallible.Ok; Assert.False(ok.Equals(new Obj())); var nok = Fallible.FromError(Error); Assert.False(nok.Equals(new Obj())); }
public static void ToString1() { var ok = Fallible.Ok; Assert.Equal("Success", ok.ToString()); var nok = Fallible.FromError(Error); Assert.Contains(Error.ToString(), nok.ToString(), StringComparison.OrdinalIgnoreCase); }
public static void ToString1() { var value = new Obj("My value"); var ok = Fallible.Of(value); Assert.Contains(value.ToString(), ok.ToString(), StringComparison.OrdinalIgnoreCase); var nok = Fallible <Obj> .FromError(Error); Assert.Contains(Error.ToString(), nok.ToString(), StringComparison.OrdinalIgnoreCase); }