Skip to content

Commit e78a686

Browse files
committed
remove LeftOptional
1 parent be116bb commit e78a686

File tree

8 files changed

+43
-575
lines changed

8 files changed

+43
-575
lines changed

src/main/java/io/jbock/util/Either.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class Either<L, R> {
3333
* @throws NullPointerException if value is {@code null}
3434
*/
3535
public static <L, R> Either<L, R> left(L value) {
36-
return Left.create(value);
36+
return new Left<>(value);
3737
}
3838

3939
/**
@@ -46,7 +46,7 @@ public static <L, R> Either<L, R> left(L value) {
4646
* @throws NullPointerException if value is {@code null}
4747
*/
4848
public static <L, R> Either<L, R> right(R value) {
49-
return Right.create(value);
49+
return new Right<>(value);
5050
}
5151

5252
/**
@@ -115,7 +115,7 @@ public abstract <R2> Either<L, R2> flatMap(
115115
* @return filter result
116116
*/
117117
public abstract Either<L, R> filter(
118-
Function<? super R, LeftOptional<? extends L>> predicate);
118+
Function<? super R, Optional<? extends L>> predicate);
119119

120120
/**
121121
* If this is a Left, returns a Left containing the result of applying the mapper function to the LHS value.
@@ -196,12 +196,12 @@ public final boolean isRight() {
196196
}
197197

198198
/**
199-
* If this is a Left, returns a {@code LeftOptional} containing the LHS value.
200-
* Otherwise returns an empty {@code LeftOptional}.
199+
* If this is a Left, returns an {@code Optional} containing the LHS value.
200+
* Otherwise returns an empty {@code Optional}.
201201
*
202202
* @return the LHS value, or {@link java.util.Optional#empty()} if this is a Right
203203
*/
204-
public abstract LeftOptional<L> getLeft();
204+
public abstract Optional<L> getLeft();
205205

206206
/**
207207
* If this is a Right, returns an {@code Optional} containing the RHS value.

src/main/java/io/jbock/util/Left.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
import java.util.function.Consumer;
66
import java.util.function.Function;
77

8+
/**
9+
* Internal implementation of a Left-Either.
10+
*
11+
* @param <L> the type of the LHS value
12+
* @param <R> the type of the RHS value
13+
*/
814
final class Left<L, R> extends Either<L, R> {
915

1016
private final L value;
1117

12-
private Left(L value) {
18+
Left(L value) {
1319
this.value = Objects.requireNonNull(value);
1420
}
1521

16-
static <L, R> Left<L, R> create(L value) {
17-
return new Left<>(value);
18-
}
19-
2022
@Override
21-
public LeftOptional<L> getLeft() {
22-
return LeftOptional.of(value);
23+
public Optional<L> getLeft() {
24+
return Optional.of(value);
2325
}
2426

2527
@Override
@@ -43,13 +45,13 @@ public <R2> Either<L, R2> flatMap(Function<? super R, ? extends Either<? extends
4345
}
4446

4547
@Override
46-
public Either<L, R> filter(Function<? super R, LeftOptional<? extends L>> predicate) {
48+
public Either<L, R> filter(Function<? super R, Optional<? extends L>> predicate) {
4749
return same();
4850
}
4951

5052
@Override
5153
public <L2> Either<L2, R> mapLeft(Function<? super L, ? extends L2> mapper) {
52-
return create(mapper.apply(value));
54+
return new Left<>(mapper.apply(value));
5355
}
5456

5557
@Override
@@ -63,7 +65,7 @@ public Either<L, R> filterLeft(Function<? super L, Optional<? extends R>> predic
6365
if (test.isEmpty()) {
6466
return same();
6567
}
66-
return Right.create(test.orElseThrow());
68+
return new Right<>(test.orElseThrow());
6769
}
6870

6971
@Override

0 commit comments

Comments
 (0)