|
3 | 3 | import com.jnape.palatable.lambda.adt.Either; |
4 | 4 | import com.jnape.palatable.lambda.functions.Fn1; |
5 | 5 | import com.jnape.palatable.lambda.functor.Applicative; |
| 6 | +import com.jnape.palatable.lambda.functor.Bifunctor; |
6 | 7 | import com.jnape.palatable.lambda.functor.builtin.Compose; |
7 | 8 | import com.jnape.palatable.lambda.functor.builtin.Lazy; |
8 | 9 | import com.jnape.palatable.lambda.monad.Monad; |
|
20 | 21 | * @param <L> the left type |
21 | 22 | * @param <R> the right type |
22 | 23 | */ |
23 | | -public final class EitherT<M extends Monad<?, M>, L, R> implements MonadT<M, Either<L, ?>, R> { |
| 24 | +public final class EitherT<M extends Monad<?, M>, L, R> implements |
| 25 | + Bifunctor<L, R, EitherT<M, ?, ?>>, |
| 26 | + MonadT<M, Either<L, ?>, R> { |
24 | 27 |
|
25 | 28 | private final Monad<Either<L, R>, M> melr; |
26 | 29 |
|
@@ -100,6 +103,31 @@ public <B> EitherT<M, L, R> discardR(Applicative<B, MonadT<M, Either<L, ?>, ?>> |
100 | 103 | return MonadT.super.discardR(appB).coerce(); |
101 | 104 | } |
102 | 105 |
|
| 106 | + /** |
| 107 | + * {@inheritDoc} |
| 108 | + */ |
| 109 | + @Override |
| 110 | + public <L2, R2> EitherT<M, L2, R2> biMap(Fn1<? super L, ? extends L2> lFn, |
| 111 | + Fn1<? super R, ? extends R2> rFn) { |
| 112 | + return eitherT(melr.fmap(e -> e.biMap(lFn, rFn))); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * {@inheritDoc} |
| 117 | + */ |
| 118 | + @Override |
| 119 | + public <L2> EitherT<M, L2, R> biMapL(Fn1<? super L, ? extends L2> fn) { |
| 120 | + return (EitherT<M, L2, R>) Bifunctor.super.<L2>biMapL(fn); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * {@inheritDoc} |
| 125 | + */ |
| 126 | + @Override |
| 127 | + public <R2> EitherT<M, L, R2> biMapR(Fn1<? super R, ? extends R2> fn) { |
| 128 | + return (EitherT<M, L, R2>) Bifunctor.super.<R2>biMapR(fn); |
| 129 | + } |
| 130 | + |
103 | 131 | @Override |
104 | 132 | public boolean equals(Object other) { |
105 | 133 | return other instanceof EitherT<?, ?, ?> && Objects.equals(melr, ((EitherT<?, ?, ?>) other).melr); |
|
0 commit comments