Ejemplo n.º 1
0
 public static Either <T2, TRight> SelectMany <T, TRight, T1, T2>(this Either <T, TRight> self, Func <T, Either <T1, TRight> > selector, Func <T, T1, T2> mapper) =>
 self.Match(
     x => selector(x).Match <Either <T2, TRight> >(
         y => mapper(x, y),
         z => z
         ),
     x => x
     );
Ejemplo n.º 2
0
 public static Either <L, RR> SelectMany <L, T, R, RR>(this Either <L, T> @this
                                                       , Func <T, Either <L, R> > bind, Func <T, R, RR> project)
 => @this.Match(
     Left: l => Left(l),
     Right: t =>
     bind(@this.Right).Match <Either <L, RR> >(
         Left: l => Left(l),
         Right: r => project(t, r)));
Ejemplo n.º 3
0
 public static Either <L, RR> Bind <L, R, RR>
     (this Either <L, R> @this, Func <R, Either <L, RR> > f)
 => @this.Match(
     l => Left(l),
     r => f(r));
Ejemplo n.º 4
0
 public static Either <LL, RR> Map <L, LL, R, RR>
     (this Either <L, R> @this, Func <L, LL> left, Func <R, RR> right)
 => @this.Match <Either <LL, RR> >(
     l => Left(left(l)),
     r => Right(right(r)));
Ejemplo n.º 5
0
 public static Either <L, RR> Map <L, R, RR>
     (this Either <L, R> @this, Func <R, RR> f)
 => @this.Match <Either <L, RR> >(
     l => Left(l),
     r => Right(f(r)));
Ejemplo n.º 6
0
 public static Either <T2, TRight2> bmap <T, TRight, T2, TRight2>(this Either <T, TRight> self, Func <T, T2> mapLeft, Func <TRight, TRight2> mapRight) =>
 self.Match <Either <T2, TRight2> >(
     x => mapLeft(x),
     x => mapRight(x)
     );
Ejemplo n.º 7
0
 public static Maybe <T> ToMaybe <T>(this Either <Unit, T> self) => self.Match(_ => Maybe.Nothing, x => Maybe.Just(x));
Ejemplo n.º 8
0
 public static Either <TRight, TLeft> Swap <TLeft, TRight>(this Either <TLeft, TRight> self) =>
 self.Match(
     x => Either <TRight, TLeft> .New(x),
     x => Either <TRight, TLeft> .New(x)
     );
Ejemplo n.º 9
0
 public static Either <T1, TRight> SelectMany <T, TRight, T1>(this Either <T, TRight> self, Func <T, Either <T1, TRight> > selector) =>
 self.Match(
     x => selector(x),
     x => x
     );
Ejemplo n.º 10
0
 public static Either <TLeftNew, TRight> Select <TLeft, TLeftNew, TRight>(this Either <TLeft, TRight> self, Func <TLeft, TLeftNew> mapper) =>
 self.Match <Either <TLeftNew, TRight> >(
     x => mapper(x),
     x => x
     );
Ejemplo n.º 11
0
 public static Either <L, RR> Map <L, R, RR>(this Either <L, R> either, Func <R, RR> func)
 => either.Match <Either <L, RR> >(l => Left(l), r => Right(func(r)));
Ejemplo n.º 12
0
 public static Either <L, P> SelectMany <L, R, RR, P>(this Either <L, R> either, Func <R, Either <L, RR> > bind,
                                                      Func <R, RR, P> project) => either.Match(
     l => Left(l),
     r => bind(either.Right).Match <Either <L, P> >(
         l => Left(l),
         rr => project(r, rr)));
Ejemplo n.º 13
0
 public static Either <L, RR> Bind <L, R, RR>(this Either <L, R> either, Func <R, RR> func)
 => either.Match <Either <L, RR> >(l => Left(l), r => func(r));