Beispiel #1
0
 public static OptionAsync <A> ToAsync <A>(this Task <Option <A> > ma) =>
 new OptionAsync <A>(OptionDataAsync.Lazy(async() =>
 {
     var a = await ma;
     return(a.IsSome
             ? new Result <A>(a.Value)
             : Result <A> .None);
 }));
Beispiel #2
0
 public OptionAsync <A> Return(Func <Unit, A> f) =>
 new OptionAsync <A>(OptionDataAsync.Lazy(() =>
                                          Task.Run(() =>
 {
     var a = f(unit);
     return(a.IsNull()
                 ? new Result <A>()
                 : new Result <A>(a));
 })));
Beispiel #3
0
 public OptionAsync <B> BiMap(OptionAsync <A> ma, Func <A, B> fa, Func <Unit, B> fb) =>
 new OptionAsync <B>(OptionDataAsync.Lazy <B>(async() =>
                                              await ma.Match(
                                                  Some: x => fa(x),
                                                  None: () => fb(unit))));