Beispiel #1
0
   public static Either <A, B> opt <A, B>(bool condition, Fn <A> ifFalse, Fn <B> ifTrue) =>
   condition
 ? Either <A, B> .Right(ifTrue())
 : Either <A, B> .Left(ifFalse());
Beispiel #2
0
 [PublicAPI] public static Future <Either <A, BB> > flatMapT <B, BB, A>(
     this Future <Either <A, B> > m, Fn <B, Future <BB> > mapper
     ) => m.flatMap(_ => _.fold(
                        err => Future.successful(Either <A, BB> .Left(err)),
                        from => mapper(from).map(Either <A, BB> .Right)
                        ));
Beispiel #3
0
   public static Either <A, B> opt <A, B>(bool condition, A ifFalse, B ifTrue) =>
   condition
 ? Either <A, B> .Right(ifTrue)
 : Either <A, B> .Left(ifFalse);
Beispiel #4
0
        public void WhenLeftEquals()
        {
            Either <int, string> .Left(0).shouldEqual(Either <int, string> .Left(0));

            Either <int, string> .Left(10).shouldEqual(Either <int, string> .Left(10));
        }
Beispiel #5
0
 [PublicAPI] public static Future <Either <A, BB> > flatMapT <A, B, BB>(
     this Future <Either <A, B> > m, Fn <B, Future <Either <A, BB> > > mapper
     ) => m.flatMap(_ => _.fold(
                        a => Future.successful(Either <A, BB> .Left(a)),
                        mapper
                        ));
Beispiel #6
0
 [Test] public void WhenLeft() =>
 Either <int, string> .Left(3)
 .toTry(onLeft)
 .shouldBeError(typeof(ArgumentException));
Beispiel #7
0
 [Test] public void WhenLeft() => Either <int, string> .Left(3).swap.shouldBeRight(3);
Beispiel #8
0
 [Test] public void WhenLeft() => Either <int, string> .Left(3).fold(folder, folder).shouldEqual('3');
Beispiel #9
0
 [Test] public void WhenLeft() => test(Either <int, string> .Left(3), '3');
Beispiel #10
0
 public Either <A, B> toLeft <B>(Fn <B> right) =>
 isSome ? Either <A, B> .Left(__unsafeGetValue) : Either <A, B> .Right(right());
Beispiel #11
0
 public Either <B, A> toRight <B>(Fn <B> left) =>
 isSome ? Either <B, A> .Right(__unsafeGetValue) : Either <B, A> .Left(left());
Beispiel #12
0
 [PublicAPI] public Either <B, A> toRight <B>(B left) =>
 isSome ? Either <B, A> .Right(__unsafeGetValue) : Either <B, A> .Left(left);
Beispiel #13
0
 [PublicAPI] public Either <A, B> toLeft <B>(B right) =>
 isSome ? Either <A, B> .Left(__unsafeGetValue) : Either <A, B> .Right(right);
Beispiel #14
0
   public static Either <ImmutableList <A>, B> asValidationErrors <A, B>(
       this ImmutableList <A> errors, Fn <B> b
       ) =>
   errors.IsEmpty
 ? Either <ImmutableList <A>, B> .Right(b())
 : Either <ImmutableList <A>, B> .Left(errors);
Beispiel #15
0
 public Either <B, A> toRight <B>(Fn <B> left)
 {
     return(isSome ? Either <B, A> .Right(value) : Either <B, A> .Left(left()));
 }
Beispiel #16
0
 public Either <A, B> toLeft <B>(Fn <B> right)
 {
     return(isSome ? Either <A, B> .Left(value) : Either <A, B> .Right(right()));
 }