public static EitherUnsafe <L, R> Flatten <L, R>(this EitherUnsafe <L, EitherUnsafe <L, R> > ma) =>
 ma.Bind(identity);
Beispiel #2
0
 public Func <Unit, S> FoldBack <S>(EitherUnsafe <L, R> foldable, S state, Func <S, R, S> f) =>
 u =>
 foldable.MatchUnsafe(
     Left: _ => state,
     Right: _ => f(state, foldable.RightValue),
     Bottom: () => state);
Beispiel #3
0
 public EitherUnsafe <L, R2> Map(EitherUnsafe <L, R> ma, Func <R, R2> f) =>
 default(MEitherUnsafe <L, R>).MatchUnsafe(ma,
                                           Left: EitherUnsafe <L, R2> .Left,
                                           Right: b => EitherUnsafe <L, R2> .Right(f(b)),
                                           Bottom: () => EitherUnsafe <L, R2> .Bottom);
Beispiel #4
0
 public EitherUnsafe <L, R> Plus(EitherUnsafe <L, R> ma, EitherUnsafe <L, R> mb) =>
 Match(ma,
       Left: _ => mb,
       Right: _ => ma,
       Bottom: () => mb);
Beispiel #5
0
 public bool IsSome(EitherUnsafe <L, R> opt) =>
 opt.IsRight;
Beispiel #6
0
 public bool IsUnsafe(EitherUnsafe <L, R> choice) =>
 true;
Beispiel #7
0
 public bool IsBottom(EitherUnsafe <L, R> choice) =>
 choice.State == EitherStatus.IsBottom;
 public int GetHashCode(EitherUnsafe <L, R> x) =>
 default(HashableEitherUnsafe <HashableDefault <L>, HashableDefault <R>, L, R>).GetHashCode(x);
 public Task <int> GetHashCodeAsync(EitherUnsafe <L, R> x) =>
 GetHashCode(x).AsTask();
 public bool Equals(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) => x.State switch
 {
 public bool Equals(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) =>
 default(EqEitherUnsafe <EqDefault <L>, EqDefault <R>, L, R>).Equals(x, y);
 public static EitherUnsafe <L, B> Apply <L, A, B>(this EitherUnsafe <L, Func <A, B> > fab, EitherUnsafe <L, A> fa) =>
 ApplEitherUnsafe <L, A, B> .Inst.Apply(fab, fa);
 public static EitherUnsafe <L, R> Divide <NUM, L, R>(this EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) where NUM : struct, Num <R> =>
 from a in x
 from b in y
 select default(NUM).Divide(a, b);
 public static EitherUnsafe <L, R> Subtract <NUM, L, R>(this EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) where NUM : struct, Num <R> =>
 from a in x
 from b in y
 select default(NUM).Subtract(a, b);
Beispiel #15
0
 public Func <Unit, Task <int> > CountAsync(EitherUnsafe <L, R> fa) => _ =>
 Task.FromResult(Inst.Count(fa)(_));
 public Task <bool> EqualsAsync(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) =>
 Equals(x, y).AsTask();
Beispiel #17
0
 public EitherUnsafe <L, R> Append(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) =>
 Plus(x, y);
Beispiel #18
0
 internal EitherUnsafeContext(EitherUnsafe <L, R> either, Func <R, Ret> rightHandler)
 {
     this.either       = either;
     this.rightHandler = rightHandler;
 }
Beispiel #19
0
 public bool IsRight(EitherUnsafe <L, R> choice) =>
 choice.State == EitherStatus.IsRight;
Beispiel #20
0
 internal EitherUnsafeUnitContext(EitherUnsafe <L, R> either, Action <R> rightHandler)
 {
     this.either       = either;
     this.rightHandler = rightHandler;
 }
Beispiel #21
0
 public EitherUnsafe <L, R> Fail(object err) =>
 err is L
         ? EitherUnsafe <L, R> .Left((L)err)
         : EitherUnsafe <L, R> .Bottom;
Beispiel #22
0
 public EitherUnsafe <L, R> BindReturn(Unit _, EitherUnsafe <L, R> mb) =>
 mb;
Beispiel #23
0
 public bool IsNone(EitherUnsafe <L, R> opt) =>
 !opt.IsRight;
Beispiel #24
0
 public Func <Unit, Task <S> > FoldBackAsync <S>(EitherUnsafe <L, R> fa, S state, Func <S, R, S> f) => _ =>
 Task.FromResult(Inst.FoldBack <S>(fa, state, f)(_));
Beispiel #25
0
 public R2 MatchUnsafe <R2>(EitherUnsafe <L, R> opt, Func <R, R2> Some, Func <R2> None) =>
 opt.IsRight
         ? Some(opt.RightValue)
         : None();
Beispiel #26
0
 public Func <Unit, Task <S> > FoldBackAsync <S>(EitherUnsafe <L, R> fa, S state, Func <S, R, Task <S> > f) => _ =>
 fa.MatchUnsafe(
     Right: r => f(state, r),
     Left: l => Task.FromResult(state),
     Bottom: () => Task.FromResult(state));
Beispiel #27
0
 public S BiFold <S>(EitherUnsafe <L, R> foldable, S state, Func <S, L, S> fa, Func <S, R, S> fb) =>
 Match(foldable,
       Left: _ => fa(state, foldable.LeftValue),
       Right: _ => fb(state, foldable.RightValue),
       Bottom: () => state);
Beispiel #28
0
 public MB Bind <MONADB, MB, B>(EitherUnsafe <L, R> ma, Func <R, MB> f) where MONADB : struct, Monad <Unit, Unit, MB, B> =>
 Match(ma,
       Left : l => default(MONADB).Fail(l),
       Right : r => f(r),
       Bottom : () => default(MONADB).Fail(BottomException.Default));
Beispiel #29
0
 public EitherUnsafe <L2, R2> BiMap(EitherUnsafe <L, R> ma, Func <L, L2> fa, Func <R, R2> fb) =>
 default(MEitherUnsafe <L, R>).MatchUnsafe(ma,
                                           Left: a => EitherUnsafe <L2, R2> .Left(Check.NullReturn(fa(a))),
                                           Right: b => EitherUnsafe <L2, R2> .Right(Check.NullReturn(fb(b))),
                                           Bottom: () => EitherUnsafe <L2, R2> .Bottom);
 public static EitherUnsafe <L, B> Action <L, A, B>(this EitherUnsafe <L, A> fa, EitherUnsafe <L, B> fb) =>
 ApplEitherUnsafe <L, A, B> .Inst.Action(fa, fb);