예제 #1
0
 public static AsyncMaybe <T> OrAsync <T>(this AsyncMaybe <T> source, [InstantHandle, NotNull] Task <AsyncMaybe <T> > otherAsync)
 {
     return(source.Match(
                some: some => Some(some).ToAsync(),
                noneAsync: none => otherAsync
                ).ToAsyncMaybe());
 }
예제 #2
0
 public static AsyncMaybe <T> OrAsync <T>(this AsyncMaybe <T> source, [InstantHandle, NotNull] Func <Task <Maybe <T> > > other)
 {
     return(source.Match(
                some: Some,
                noneAsync: none => other()
                ).ToAsyncMaybe());
 }
예제 #3
0
 public static AsyncMaybe <T> Or <T>(this AsyncMaybe <T> source, AsyncMaybe <T> other)
 {
     return(source.Match(
                some: Some,
                noneAsync: none => other.ToTask()
                ).ToAsyncMaybe());
 }
예제 #4
0
 public static Task <T> OrGetAsync <T>(this AsyncMaybe <T> source, [InstantHandle, NotNull] Func <Task <T> > value)
 {
     return(source.Match(
                some => some,
                none => value()
                ));
 }
 public static Task <IEnumerable <T> > ToEnumerable <T>(this AsyncMaybe <T> source)
 {
     return(source.Match(
                some => Enumerable.Repeat(some, 1),
                none => none.ToEnumerable <T>()
                ));
 }
예제 #6
0
 public static Task <T> OrDefault <T>(this AsyncMaybe <T> source)
 {
     return(source.Match(
                some => some,
                none => default(T)
                ));
 }
예제 #7
0
 public static Task <T> OrReturnAsync <T>(this AsyncMaybe <T> source, Task <T> value)
 {
     return(source.Match(
                some => some,
                none => value
                ));
 }
예제 #8
0
 public static Task <T> OrThrow <T>(this AsyncMaybe <T> source, [InstantHandle, NotNull] Func <Exception> exception)
 {
     return(source.Match(
                some => some,
                none: _ => throw exception()
                ));
 }
예제 #9
0
        public static AsyncMaybe <T> Flatten <T>(this AsyncMaybe <Maybe <T> > source)
        {
            var t = source.Match <AsyncMaybe <T> >(
                some: outerValue => new AsyncMaybe <T>(Task.FromResult <Maybe <T> >(outerValue)),
                none: none => AsyncMaybe <T> .None()
                );

            return(t.ToAsyncMaybe());
        }
예제 #10
0
 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());
 }
 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> 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> 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());
 }
예제 #15
0
 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 <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());
 }
예제 #17
0
 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());
 }