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()); }
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()); }