public static AsyncMaybe <T> Filter <T>( this AsyncMaybe <T> source, [InstantHandle, NotNull] Func <T, bool> predicate) { return(source.Match( some => predicate(some) ? Maybe <T> .Some(some) : Maybe <T> .None(), none => Maybe <T> .None() ).ToAsyncMaybe()); }
Flattening_From_String_Maybe_With_value_To_Nullable_Int_With_Value__Expects_String_Maybe_With_Value() { const string input = "hello"; int? nullabelInt = 2; await AsyncMaybe.Value(input) .FlatMapAsync(async x => { await AssertionUtilities.Delay; return(nullabelInt); }) .AssertValue(nullabelInt.Value); }
public static AsyncMaybe <T> Flatten <T>(this AsyncMaybe <AsyncMaybe <T> > source) { var t = source.Match <AsyncMaybe <T> >( someAsync: async outerValue => await outerValue.Match <AsyncMaybe <T> >( some: innerValue => new AsyncMaybe <T>(Task.FromResult <Maybe <T> >(Some <T>(innerValue))), none: none => AsyncMaybe <T> .None() ), none: none => AsyncMaybe <T> .None() ); return(t.ToAsyncMaybe()); }
ResultSelector_Overload__Flattening_From_String_Maybe_With_value_To_Nullable_Int_Without_Value__Expects_String_Maybe_Without_Value() { const string input = "hello"; int? nullableInt = null; await AsyncMaybe.Value(input) .FlatMapAsync(async x => { await AssertionUtilities.Delay; return(nullableInt); }, (x, y) => x.Length + y) .AssertNone(); }
public static AsyncMaybe <TResult> Zip <T1, T2, TResult>( this AsyncMaybe <T1> first, AsyncMaybe <T2> second, [InstantHandle, NotNull] Func <T1, T2, TResult> zipper ) { if (zipper == null) { throw new ArgumentNullException(nameof(zipper)); } return(first.FlatMap( some1 => second.Map( some2 => zipper(some1, some2) ) )); }
public static AsyncMaybe <TResult> Zip <T1, T2, T3, T4, TResult>( this AsyncMaybe <T1> first, AsyncMaybe <T2> second, AsyncMaybe <T3> third, AsyncMaybe <T4> fourth, [InstantHandle, NotNull] Func <T1, T2, T3, T4, TResult> zipper ) { if (zipper == null) { throw new ArgumentNullException(nameof(zipper)); } return(first.FlatMap <T1, TResult>( some1 => second.FlatMap <T2, TResult>( some2 => third.FlatMap <T3, TResult>( some3 => fourth.Map <T4, TResult>( some4 => zipper(some1, some2, some3, some4) ) ) ) )); }
public static Task <Maybe <T> > ToTask <T>(this AsyncMaybe <T> source) { return(source.Match(some: Some, none: none => Maybe <T> .None())); }
public static AsyncMaybe <TResult> Select <T, TResult>( this AsyncMaybe <T> source, [NotNull] Func <T, TResult> mapper ) => source.Map(mapper);
public static AsyncMaybe <T> Where <T>( this AsyncMaybe <T> source, [NotNull] Func <T, bool> predicate ) => source.Filter(predicate);
public static AsyncMaybe <Unit> Map <T>( this AsyncMaybe <T> source, [NotNull] Action <T> mapper) { return(source.Match(some => AsyncMaybe <Unit> .Some(mapper.WithUnitResult()(some)), none: AsyncMaybe <Unit> .None).ToAsyncMaybe()); }
ResultSelector_Overload__Flattening_From_String_Maybe_Without_value_To_String_Maybe_Without_Value__Expects_String_Maybe_Without_Value() { await AsyncMaybe.None <string>() .FlatMapAsync(x => AsyncMaybe.None <string>()) .AssertNone(); }
public static AsyncMaybe <TResult> FlatMapUnitAsync <TResult>( this AsyncMaybe <Unit> source, [NotNull] Func <Task <AsyncMaybe <TResult> > > mapper) { return(source.Match(unit => mapper(), none: AsyncMaybe <TResult> .None).ToAsyncMaybe()); }
public static AsyncMaybe <TResult> MapAsync <T, TResult>( this AsyncMaybe <T> source, [NotNull] Func <T, Task <TResult> > mapperAsync) { return(source.Match(some => mapperAsync(some).Then(Some), none => Maybe <TResult> .None()).ToAsyncMaybe()); }
public static AsyncMaybe <T> WhereAsync <T>( this AsyncMaybe <T> source, [NotNull] Func <T, Task <bool> > predicate ) => source.FilterAsync(predicate);
public static AsyncMaybe <Unit> MapAsync <T>( this AsyncMaybe <T> source, [NotNull] Func <Task> mapperAsync) { return(source.Match(some => mapperAsync().Then(() => Some(default(Unit))), none => Maybe <Unit> .None()).ToAsyncMaybe()); }
public static AsyncMaybe <T> ToAsyncMaybe <T>(this None none) { return(AsyncMaybe <T> .None()); }
ResultSelector_Overload__Flattening_From_String_Maybe_Without_value_To_String_Maybe_With_Value__Expects_String_Maybe_Without_Value() { await AsyncMaybe.None <string>() .FlatMapAsync(x => AsyncMaybe.Value("hello"), (x, y) => x.Length + y.Length); }
public static AsyncMaybe <TResult> FlatMapAsync <T, TResult>( this AsyncMaybe <T> source, [NotNull] Func <T, Task <Maybe <TResult> > > mapper) { return(source.Match(mapper, none => Maybe <TResult> .None()).ToAsyncMaybe()); }
public static AsyncMaybe <TResult> Map <T, TResult>( this AsyncMaybe <T> source, [NotNull] Func <T, TResult> mapper) { return(source.Match(some => AsyncMaybe <TResult> .Some(mapper(some)), none: AsyncMaybe <TResult> .None).ToAsyncMaybe()); }
public static AsyncMaybe <Unit> Select <T>( this AsyncMaybe <T> source, [NotNull] Action <T> mapper ) => source.Map(mapper);