|
1 | 1 | package com.jnape.palatable.lambda.adt;
|
2 | 2 |
|
| 3 | +import com.jnape.palatable.lambda.adt.coproduct.CoProduct2; |
| 4 | +import com.jnape.palatable.lambda.functions.specialized.checked.CheckedFn1; |
3 | 5 | import com.jnape.palatable.lambda.functions.specialized.checked.CheckedSupplier;
|
4 |
| -import com.jnape.palatable.lambda.functor.Bifunctor; |
5 |
| -import com.jnape.palatable.lambda.functor.Functor; |
6 | 6 |
|
7 | 7 | import java.util.Objects;
|
8 | 8 | import java.util.Optional;
|
|
23 | 23 | * @param <L> The left parameter type
|
24 | 24 | * @param <R> The right parameter type
|
25 | 25 | */
|
26 |
| -public abstract class Either<L, R> implements Functor<R>, Bifunctor<L, R> { |
| 26 | +public abstract class Either<L, R> implements CoProduct2<L, R> { |
27 | 27 |
|
28 | 28 | private Either() {
|
29 | 29 | }
|
@@ -61,16 +61,16 @@ public final L forfeit(Function<? super R, ? extends L> forfeitFn) {
|
61 | 61 | }
|
62 | 62 |
|
63 | 63 | /**
|
64 |
| - * Return the wrapped value if this is a right; otherwise, map the wrapped left value to an <code>E</code> and throw |
| 64 | + * Return the wrapped value if this is a right; otherwise, map the wrapped left value to a <code>T</code> and throw |
65 | 65 | * it.
|
66 | 66 | *
|
67 |
| - * @param throwableFn a function from L to E |
68 |
| - * @param <E> the left parameter type (the throwable exception type) |
| 67 | + * @param throwableFn a function from L to T |
| 68 | + * @param <T> the left parameter type (the throwable type) |
69 | 69 | * @return the wrapped value if this is a right
|
70 |
| - * @throws E the result of applying the wrapped left value to throwableFn, if this is a left |
| 70 | + * @throws T the result of applying the wrapped left value to throwableFn, if this is a left |
71 | 71 | */
|
72 |
| - public final <E extends RuntimeException> R orThrow(Function<? super L, ? extends E> throwableFn) throws E { |
73 |
| - return match(l -> { |
| 72 | + public final <T extends Throwable> R orThrow(Function<? super L, ? extends T> throwableFn) throws T { |
| 73 | + return match((CheckedFn1<T, L, R>) l -> { |
74 | 74 | throw throwableFn.apply(l);
|
75 | 75 | }, id());
|
76 | 76 | }
|
@@ -200,13 +200,13 @@ public final <R2> Either<L, R2> fmap(Function<? super R, ? extends R2> fn) {
|
200 | 200 | @Override
|
201 | 201 | @SuppressWarnings("unchecked")
|
202 | 202 | public final <L2> Either<L2, R> biMapL(Function<? super L, ? extends L2> fn) {
|
203 |
| - return (Either<L2, R>) Bifunctor.super.biMapL(fn); |
| 203 | + return (Either<L2, R>) CoProduct2.super.biMapL(fn); |
204 | 204 | }
|
205 | 205 |
|
206 | 206 | @Override
|
207 | 207 | @SuppressWarnings("unchecked")
|
208 | 208 | public final <R2> Either<L, R2> biMapR(Function<? super R, ? extends R2> fn) {
|
209 |
| - return (Either<L, R2>) Bifunctor.super.biMapR(fn); |
| 209 | + return (Either<L, R2>) CoProduct2.super.biMapR(fn); |
210 | 210 | }
|
211 | 211 |
|
212 | 212 | @Override
|
|
0 commit comments