Skip to content

Commit 19253b7

Browse files
committed
rename asLeftOptional to optionalList
1 parent 2827d2c commit 19253b7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static <L, R> Either<L, R> right(R value) {
8787
* @return an {@code Optional} which is empty if and only if {@code failures}
8888
* is empty
8989
*/
90-
public static <L> Optional<List<L>> asLeftOptional(List<? extends L> failures) {
90+
public static <L> Optional<List<L>> optionalList(List<? extends L> failures) {
9191
if (failures.isEmpty()) {
9292
return Optional.empty();
9393
}

src/test/java/io/jbock/util/EitherTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.jupiter.api.Test;
55

66
import java.io.IOException;
7+
import java.util.List;
78
import java.util.Objects;
89
import java.util.Optional;
910

@@ -134,4 +135,11 @@ void testOrElseThrow() {
134135
Either<String, String> right = Either.right("2");
135136
assertEquals("2", right.orElseThrow(IllegalArgumentException::new));
136137
}
138+
139+
@Test
140+
void testOptionalList() {
141+
assertEquals(Optional.empty(), Either.optionalList(List.of()));
142+
assertEquals(Optional.of(List.of(1)), Either.optionalList(List.of(1)));
143+
assertEquals(Optional.of(List.of("1", "2")), Either.optionalList(List.of("1", "2")));
144+
}
137145
}

0 commit comments

Comments
 (0)