예제 #1
0
        /// <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))));
        }
예제 #2
0
 public static Fallible <TResult> InvokeWith <TSource, TResult>(
     this Func <TSource, Fallible <TResult> > @this,
     Fallible <TSource> value)
 {
     /* T4: NotNull(value) */
     return(value.Bind(@this));
 }
예제 #3
0
 public static Fallible <TResult> ContinueWith <TSource, TResult>(
     this Fallible <TSource> @this,
     Fallible <TResult> other)
 {
     /* T4: NotNull(@this) */
     return(@this.Bind(_ => other));
 }
예제 #4
0
 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))));
 }
예제 #5
0
 /// <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)));
 }
예제 #6
0
 // 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); } }));
 }
예제 #7
0
        // Generalizes both Bind() and ZipWith<T1, T2, TResult>().
        public static Fallible <TResult> SelectMany <TSource, TMiddle, TResult>(
            this Fallible <TSource> @this,
            Func <TSource, Fallible <TMiddle> > selector,
            Func <TSource, TMiddle, TResult> resultSelector)
        {
            /* T4: NotNull(@this) */
            Require.NotNull(selector, nameof(selector));
            Require.NotNull(resultSelector, nameof(resultSelector));

            return(@this.Bind(
                       val => selector(val).Select(
                           middle => resultSelector(val, middle))));
        }
예제 #8
0
        /// <seealso cref="Fallible.Lift{T1, T2, TResult}"/>
        public static Fallible <TResult> ZipWith <T1, T2, TResult>(
            this Fallible <T1> @this,
            Fallible <T2> second,
            Func <T1, T2, TResult> zipper)
        {
            /* T4: NotNull(@this) */
            /* T4: NotNull(second) */
            Require.NotNull(zipper, nameof(zipper));

            return(@this.Bind(
                       arg1 => second.Select(
                           arg2 => zipper(arg1, arg2))));
        }
예제 #9
0
        /// <seealso cref="Fallible.Lift{T1, T2, T3, TResult}"/>
        public static Fallible <TResult> ZipWith <T1, T2, T3, TResult>(
            this Fallible <T1> @this,
            Fallible <T2> second,
            Fallible <T3> third,
            Func <T1, T2, T3, TResult> zipper)
        {
            /* T4: NotNull(@this) */
            /* T4: NotNull(second) */
            /* T4: NotNull(third) */
            Require.NotNull(zipper, nameof(zipper));

            // This is the same as:
            // > return @this.Bind(
            // >     arg1 => second.Bind(
            // >        arg2 => third.Select(
            // >            arg3 => zipper(arg1, arg2, arg3))));
            // but faster if ZipWith is locally shadowed.
            return(@this.Bind(
                       arg1 => second.ZipWith(
                           third, (arg2, arg3) => zipper(arg1, arg2, arg3))));
        }