Пример #1
0
 // Exceptional
 public static Exceptional <IEnumerable <R> > Traverse <T, R>(this IEnumerable <T> list, Func <T, Exceptional <R> > func)
 => list.Aggregate(
     seed: Exceptional.Of(Enumerable.Empty <R>()),
     // Exceptional<R> -> T -> Exceptional<[R]>
     func: (optRs, t) => from rs in optRs
     from r in func(t)
     select rs.Append(r));
Пример #2
0
 Exception ExceptionOrDefault(Exceptional <T> ex)
 => ex.Match(exc => exc, _ => default(Exception));
Пример #3
0
 T ValueOrDefault(Exceptional <T> ex)
 => ex.Match(exc => default(T), t => t);
Пример #4
0
 bool IsSuccess(Exceptional <T> ex)
 => ex.Match(_ => false, _ => true);
Пример #5
0
 public static Validation<Exceptional<R>> Traverse<T, R>
    (this Exceptional<T> tr, Func<T, Validation<R>> f)
    => tr.Match(
       Exception: e => Valid((Exceptional<R>)e),
       Success: t => from r in f(t) select Exceptional(r));