コード例 #1
0
        public static IOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, Option <TBind> > bind, Func <TSuccess, TBind, TResult> resultSelector)
            where TSuccess : 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)),
                                  Option.None <TResult>
                                  )
                           )
                   .AsOptionEnumerable());
        }
コード例 #2
0
 public static IOptionEnumerable <TValue> Where <TValue>(this IOptionEnumerable <TValue> source, Func <TValue, Option <Unit> > failurePredicate)
 => source
 .Select((Func <Option <TValue>, Option <TValue> >)(value => value
                                                    .Bind((Func <TValue, Option <TValue> >)(success => (Option <TValue>)OptionExtensions.Map <Unit, TValue>(failurePredicate
                                                                                                                                                            .Invoke((TValue)success)
                                                                                                                                                            , (Func <Unit, TValue>)(_ => (TValue)success)))
                                                          ))
         )
 .AsOptionEnumerable();
コード例 #3
0
 public static IOptionEnumerable <TValue> Where <TValue>(this IOptionEnumerable <TValue> source, Func <TValue, Option <Unit> > failurePredicate)
 => source
 .Select(value => value
         .Bind(success => failurePredicate
               .Invoke(success)
               .Select(_ => success)
               )
         )
 .AsOptionEnumerable();
コード例 #4
0
        public static IOptionEnumerable <TResult> Select <TSuccess, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, TResult> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source
                   .Select(result => result
                           .Match(
                               success => Option.Some(selector.Invoke(success)),
                               Option.None <TResult>
                               )
                           )
                   .AsOptionEnumerable());
        }