Right-bias Either and add some useful methods
package org.openqa.selenium.internal;
-public class Either<A, B> {
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+public class Either<A, B> implements Iterable<B> {
private final A left;
private final B right;
@@ -49,4 +54,23 @@ public A left() {
public B right() {
return right;
}
+
+ public <R> R map(Function<? super B, ? extends R> mapper) {
+ Require.nonNull("Mapper", mapper);
+ return mapper.apply(right());
+ }
+
+ public <R> R mapLeft(Function<? super A, ? extends R> mapper) {
+ Require.nonNull("Mapper", mapper);
+ return mapper.apply(left());
+ }
+
+ @Override
+ public Iterator<B> iterator() {
+ return Collections.singleton(right()).iterator();
+ }
+
+ public Stream<B> stream() {
+ return Stream.of(right());
+ }
}
