Exemplo n.º 1
0
Arquivo: F.java Projeto: gspandy/utils
 public <X> Either<A, B> fold(Action<A> fa, Action<B> fb) {
   if (isLeft()) {
     fa.apply(left.get());
     return new Either<A, B>(left.get(), null);
   } else if (isRight()) {
     fb.apply(right.get());
     return new Either<A, B>(null, right.get());
   } else {
     return new Either<A, B>(null, null);
   }
 }
Exemplo n.º 2
0
Arquivo: F.java Projeto: gspandy/utils
 public <X> Option<X> fold(Function<A, X> fa, Function<B, X> fb) {
   if (isLeft()) {
     return Option.maybe(fa.apply(left.get()));
   } else if (isRight()) {
     return Option.maybe(fb.apply(right.get()));
   } else {
     return (Option<X>) Option.none();
   }
 }
Exemplo n.º 3
0
Arquivo: F.java Projeto: gspandy/utils
 public Either<B, A> swap() {
   A vLeft = null;
   B vRight = null;
   if (left.isDefined()) {
     vLeft = left.get();
   }
   if (right.isDefined()) {
     vRight = right.get();
   }
   return new Either<B, A>(vRight, vLeft);
 }