public static IResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <TBind, TFailure> > bind, Func <TSuccess, TBind, TResult> resultSelector)
            where TSuccess : notnull
            where TFailure : notnull
            where TBind : notnull
            where TResult : notnull
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(source
                   .Select(result => result
                           .Match(success =>
                                  bind
                                  .Invoke(success)
                                  .Map(value => resultSelector.Invoke(success, value)),
                                  Result.Failure <TResult, TFailure>
                                  )
                           )
                   .AsResultEnumerable());
        }
 public static IResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <Unit, TFailure> > failurePredicate)
 => source
 .Select(value => value
         .Bind(success => failurePredicate
               .Invoke(success)
               .Select(_ => success)
               )
         )
 .AsResultEnumerable();
예제 #3
0
 public static IResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <Unit, TFailure> > failurePredicate)
 => source
 .Select((Func <Result <TSuccess, TFailure>, Result <TSuccess, TFailure> >)(value => value
                                                                            .Bind((Func <TSuccess, Result <TSuccess, TFailure> >)(success => (Result <TSuccess, TFailure>)ResultExtensions.Map <Unit, TFailure, TSuccess>(failurePredicate
                                                                                                                                                                                                                          .Invoke((TSuccess)success)
                                                                                                                                                                                                                          , (Func <Unit, TSuccess>)(_ => (TSuccess)success)))
                                                                                  ))
         )
 .AsResultEnumerable();
예제 #4
0
        public static IResultEnumerable <TResult, TFailure> Select <TSuccess, TResult, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, TResult> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source
                   .Select(result => result
                           .Match(
                               success => Result.Success <TResult, TFailure>(selector.Invoke(success)),
                               Result.Failure <TResult, TFailure>
                               )
                           )
                   .AsResultEnumerable());
        }