Skip to content

Commit 206afa6

Browse files
committed
Merge pull request #121 from javafp/either-bimap
Add bimap to Either
2 parents a78291f + 949e0c3 commit 206afa6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/src/main/java/fj/data/Either.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ public final <X> X either(final F<A, X> left, final F<B, X> right) {
7878
right.f(right().value());
7979
}
8080

81+
/**
82+
* Map the given functions across the appropriate side.
83+
*
84+
* @param left The function to map if this is left.
85+
* @param right The function to map if this is right.
86+
* @return A new either value after mapping with the appropriate function applied.
87+
*/
88+
public final <X, Y> Either<X, Y> bimap(final F<A, X> left, final F<B, Y> right) {
89+
return isLeft() ?
90+
left(left.f(left().value())) :
91+
right(right.f(right().value()));
92+
}
93+
8194
@Override
8295
public boolean equals(Object other) {
8396

0 commit comments

Comments
 (0)