public static EitherUnsafe <L, R> Flatten <L, R>(this EitherUnsafe <L, EitherUnsafe <L, R> > ma) =>
 ma.Bind(identity);
Exemplo n.º 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);
Exemplo n.º 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);
Exemplo n.º 4
0
 public EitherUnsafe <L, R> Plus(EitherUnsafe <L, R> ma, EitherUnsafe <L, R> mb) =>
 Match(ma,
       Left: _ => mb,
       Right: _ => ma,
       Bottom: () => mb);
Exemplo n.º 5
0
 public bool IsSome(EitherUnsafe <L, R> opt) =>
 opt.IsRight;
Exemplo n.º 6
0
 public bool IsUnsafe(EitherUnsafe <L, R> choice) =>
 true;
Exemplo n.º 7
0
 public bool IsBottom(EitherUnsafe <L, R> choice) =>
 choice.State == EitherStatus.IsBottom;
Exemplo n.º 8
0
 public int GetHashCode(EitherUnsafe <L, R> x) =>
 default(HashableEitherUnsafe <HashableDefault <L>, HashableDefault <R>, L, R>).GetHashCode(x);
Exemplo n.º 9
0
 public Task <int> GetHashCodeAsync(EitherUnsafe <L, R> x) =>
 GetHashCode(x).AsTask();
Exemplo n.º 10
0
 public bool Equals(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) => x.State switch
 {
Exemplo n.º 11
0
 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);
Exemplo n.º 15
0
 public Func <Unit, Task <int> > CountAsync(EitherUnsafe <L, R> fa) => _ =>
 Task.FromResult(Inst.Count(fa)(_));
Exemplo n.º 16
0
 public Task <bool> EqualsAsync(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) =>
 Equals(x, y).AsTask();
Exemplo n.º 17
0
 public EitherUnsafe <L, R> Append(EitherUnsafe <L, R> x, EitherUnsafe <L, R> y) =>
 Plus(x, y);
Exemplo n.º 18
0
 internal EitherUnsafeContext(EitherUnsafe <L, R> either, Func <R, Ret> rightHandler)
 {
     this.either       = either;
     this.rightHandler = rightHandler;
 }
Exemplo n.º 19
0
 public bool IsRight(EitherUnsafe <L, R> choice) =>
 choice.State == EitherStatus.IsRight;
Exemplo n.º 20
0
 internal EitherUnsafeUnitContext(EitherUnsafe <L, R> either, Action <R> rightHandler)
 {
     this.either       = either;
     this.rightHandler = rightHandler;
 }
Exemplo n.º 21
0
 public EitherUnsafe <L, R> Fail(object err) =>
 err is L
         ? EitherUnsafe <L, R> .Left((L)err)
         : EitherUnsafe <L, R> .Bottom;
Exemplo n.º 22
0
 public EitherUnsafe <L, R> BindReturn(Unit _, EitherUnsafe <L, R> mb) =>
 mb;
Exemplo n.º 23
0
 public bool IsNone(EitherUnsafe <L, R> opt) =>
 !opt.IsRight;
Exemplo n.º 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)(_));
Exemplo n.º 25
0
 public R2 MatchUnsafe <R2>(EitherUnsafe <L, R> opt, Func <R, R2> Some, Func <R2> None) =>
 opt.IsRight
         ? Some(opt.RightValue)
         : None();
Exemplo n.º 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));
Exemplo n.º 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);
Exemplo n.º 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));
Exemplo n.º 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);