Ejemplo n.º 1
0
 public static ValueTask <Option <T, TExceptionResult> > MapExceptionAsync <T, TException, TExceptionResult>(this Option <T, TException> option, Func <TException, ValueTask <TExceptionResult> > mapping) =>
 option.MatchAsync(
     some: val => new ValueTask <Option <T, TExceptionResult> >(Option.Some <T, TExceptionResult>(val)),
     none: async err => Option.None <T, TExceptionResult>(await mapping(err)));
Ejemplo n.º 2
0
 public static ValueTask <Option <T> > FilterAsync <T>(this Option <T> option, Func <T, ValueTask <bool> > predicate) =>
 option.MatchAsync(
     async x => await predicate(x) ?
     option :
     Option.None <T>(),
     () => option);
Ejemplo n.º 3
0
 public static ValueTask <Option <TResult, TException> > FlatMapAsync <T, TException, TResult>(this Option <T> option, Func <T, ValueTask <Option <TResult, TException> > > mapping, TException exception) =>
 option.MatchAsync(
     some: async val => await mapping(val),
     none: () => Option.None <TResult, TException>(exception));
Ejemplo n.º 4
0
 public static ValueTask <Option <TResult> > MapAsync <T, TResult>(this Option <T> option, Func <T, ValueTask <TResult> > mapping) =>
 option.MatchAsync(
     some: async val => (await mapping(val)).Some <TResult>(),
     none: () => Option.None <TResult>());
Ejemplo n.º 5
0
 public static ValueTask <Option <T, TException> > FilterAsync <T, TException>(this Option <T, TException> option, Func <T, ValueTask <bool> > predicate, TException exception) =>
 option.MatchAsync(
     async x => await predicate(x) ?
     option :
     Option.None <T, TException>(exception),
     _ => option);