public static IAsyncOptionEnumerable <TValue> Where <TValue>(this IOptionEnumerable <TValue> source, Func <TValue, Task <Option <Unit> > > failurePredicate)
 => source
 .SelectAsync(value => value
              .BindAsync(success => failurePredicate
                         .Invoke(success)
                         .Map(_ => success)
                         )
              )
 .AsAsyncOptionEnumerable();
 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();
 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();
        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());
        }
Ejemplo n.º 5
0
        public static IAsyncOptionEnumerable <TResult> Select <TSuccess, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, Task <TResult> > selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source
                   .SelectAsync(result => result
                                .MatchAsync(
                                    success => Option.SomeAsync(selector.Invoke(success)),
                                    () => Task.FromResult(Option.None <TResult>())
                                    )
                                )
                   .AsAsyncOptionEnumerable());
        }
Ejemplo n.º 6
0
 public OptionGroupByEnumerable(IOptionEnumerable <TSuccess> successEnumerable, Func <TSuccess, TKey> keySelector, Func <TSuccess, TElement> elementSelector)
 {
     _successEnumerable = successEnumerable;
     _keySelector       = keySelector;
     _elementSelector   = elementSelector;
 }
Ejemplo n.º 7
0
 public static IOptionEnumerable <IGrouping <TKey, TElement> > GroupBy <TKey, TSuccess, TElement>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, TKey> keySelector, Func <TSuccess, TElement> elementSelector)
 => new OptionGroupByEnumerable <TKey, TSuccess, TElement>(source, keySelector, elementSelector);
Ejemplo n.º 8
0
 public static IOptionEnumerable <IGrouping <TKey, TSuccess> > GroupBy <TKey, TSuccess>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, TKey> keySelector)
     where TSuccess : notnull
 => new OptionGroupByEnumerable <TKey, TSuccess, TSuccess>(source, keySelector, _ => _);
        public static IAsyncOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, Task <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
                   .AsAsyncEnumerable()
                   .SelectAsync(result => result
                                .MatchAsync(success =>
                                            bind
                                            .Invoke(success)
                                            .Map(value => resultSelector.Invoke(success, value)),
                                            () => Task.FromResult(Option.None <TResult>())
                                            )
                                )
                   .AsAsyncOptionEnumerable());
        }
        public static IAsyncOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, IAsyncEnumerable <TBind> > bind, Func <TSuccess, TBind, TResult> resultSelector)
            where TSuccess : notnull
            where TResult : notnull
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

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

            return(source
                   .SelectMany(result => result
                               .Match(success =>
                                      bind
                                      .Invoke(success)
                                      .Select(obj => resultSelector.Invoke(success, obj))
                                      .Select(Option.Some),
                                      () => AsyncEnumerable.Repeat(Option.None <TResult>(), 1)
                                      )
                               )
                   .AsAsyncOptionEnumerable());
        }
        public static IOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IOptionEnumerable <TSuccess> source, Func <TSuccess, Option <TBind> > bind, Func <TSuccess, TBind, TResult> resultSelector)
        {
            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)
                                  .Select(value => resultSelector.Invoke(success, value)),
                                  Option.None <TResult>
                                  )
                           )
                   .AsOptionEnumerable());
        }