コード例 #1
0
        /// <seealso cref="Either.Lift{T1, T2, T3, T4, T5, TResult, TRight}"/>
        public static Either <TResult, TRight> ZipWith <T1, T2, T3, T4, T5, TResult, TRight>(
            this Either <T1, TRight> @this,
            Either <T2, TRight> second,
            Either <T3, TRight> third,
            Either <T4, TRight> fourth,
            Either <T5, TRight> fifth,
            Func <T1, T2, T3, T4, T5, TResult> zipper)
        {
            Require.NotNull(@this, nameof(@this));
            Require.NotNull(second, nameof(second));
            Require.NotNull(third, nameof(third));
            Require.NotNull(fourth, nameof(fourth));
            Require.NotNull(fifth, nameof(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 Either <TResult, TRight> InvokeWith <TSource, TResult, TRight>(
     this Func <TSource, Either <TResult, TRight> > @this,
     Either <TSource, TRight> value)
 {
     Require.NotNull(value, nameof(value));
     return(value.Bind(@this));
 }
コード例 #3
0
 public static Either <TResult, TRight> ContinueWith <TSource, TResult, TRight>(
     this Either <TSource, TRight> @this,
     Either <TResult, TRight> other)
 {
     Require.NotNull(@this, nameof(@this));
     return(@this.Bind(_ => other));
 }
コード例 #4
0
 public static Either <TResult, TRight> Select <TSource, TResult, TRight>(
     this Either <TSource, TRight> @this,
     Func <TSource, TResult> selector)
 {
     Require.NotNull(@this, nameof(@this));
     Require.NotNull(selector, nameof(selector));
     return(@this.Bind(val => Either <TResult, TRight> .OfLeft(selector(val))));
 }
コード例 #5
0
 /// <seealso cref="Apply{TSource, TResult, TRight}(Either{Func{TSource, TResult}, TRight}, Either{TSource, TRight})" />
 public static Either <TResult, TRight> Gather <TSource, TResult, TRight>(
     this Either <TSource, TRight> @this,
     Either <Func <TSource, TResult>, TRight> applicative)
 {
     Require.NotNull(@this, nameof(@this));
     Require.NotNull(applicative, nameof(applicative));
     return(applicative.Bind(func => @this.Select(func)));
 }
コード例 #6
0
 // Bind() with automatic resource management.
 public static Either <TResult, TRight> Using <TSource, TResult, TRight>(
     this Either <TSource, TRight> @this,
     Func <TSource, Either <TResult, TRight> > binder)
     where TSource : IDisposable
 {
     Require.NotNull(@this, nameof(@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 Either <TResult, TRight> SelectMany <TSource, TMiddle, TResult, TRight>(
            this Either <TSource, TRight> @this,
            Func <TSource, Either <TMiddle, TRight> > selector,
            Func <TSource, TMiddle, TResult> resultSelector)
        {
            Require.NotNull(@this, nameof(@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="Either.Lift{T1, T2, TResult, TRight}"/>
        public static Either <TResult, TRight> ZipWith <T1, T2, TResult, TRight>(
            this Either <T1, TRight> @this,
            Either <T2, TRight> second,
            Func <T1, T2, TResult> zipper)
        {
            Require.NotNull(@this, nameof(@this));
            Require.NotNull(second, nameof(second));
            Require.NotNull(zipper, nameof(zipper));

            return(@this.Bind(
                       arg1 => second.Select(
                           arg2 => zipper(arg1, arg2))));
        }
コード例 #9
0
        /// <seealso cref="Either.Lift{T1, T2, T3, TResult, TRight}"/>
        public static Either <TResult, TRight> ZipWith <T1, T2, T3, TResult, TRight>(
            this Either <T1, TRight> @this,
            Either <T2, TRight> second,
            Either <T3, TRight> third,
            Func <T1, T2, T3, TResult> zipper)
        {
            Require.NotNull(@this, nameof(@this));
            Require.NotNull(second, nameof(second));
            Require.NotNull(third, nameof(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))));
        }