Skip to content

Commit d8f0ba0

Browse files
committed
Right-bias Either and add some useful methods
1 parent 5630155 commit d8f0ba0

File tree

1 file changed

+25
-1
lines changed
  • java/client/src/org/openqa/selenium/internal

1 file changed

+25
-1
lines changed

java/client/src/org/openqa/selenium/internal/Either.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
package org.openqa.selenium.internal;
1919

20-
public class Either<A, B> {
20+
import java.util.Collections;
21+
import java.util.Iterator;
22+
import java.util.function.Function;
23+
import java.util.stream.Stream;
24+
25+
public class Either<A, B> implements Iterable<B> {
2126
private final A left;
2227
private final B right;
2328

@@ -49,4 +54,23 @@ public A left() {
4954
public B right() {
5055
return right;
5156
}
57+
58+
public <R> R map(Function<? super B, ? extends R> mapper) {
59+
Require.nonNull("Mapper", mapper);
60+
return mapper.apply(right());
61+
}
62+
63+
public <R> R mapLeft(Function<? super A, ? extends R> mapper) {
64+
Require.nonNull("Mapper", mapper);
65+
return mapper.apply(left());
66+
}
67+
68+
@Override
69+
public Iterator<B> iterator() {
70+
return Collections.singleton(right()).iterator();
71+
}
72+
73+
public Stream<B> stream() {
74+
return Stream.of(right());
75+
}
5276
}

0 commit comments

Comments
 (0)