Skip to content

Commit f040341

Browse files
committed
Add first class either catamorphism
1 parent 6acd800 commit f040341

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,17 @@ public static <A, B> Either<A, B> right(final B b) {
737737
return new Right<>(b);
738738
}
739739

740+
/**
741+
* First class catamorphism for either. Folds over this either breaking into left or right.
742+
*
743+
* @param left The function to call if this is left.
744+
* @param right The function to call if this is right.
745+
* @return The reducing function.
746+
*/
747+
public static <A, B, X> F<Either<A,B>, X> cata(final F<A, X> left, final F<B, X> right) {
748+
return e -> e.either(left, right);
749+
}
750+
740751
/**
741752
* @return A function that maps another function across an either's left projection.
742753
*/

0 commit comments

Comments
 (0)