Skip to content

Commit 7c2605e

Browse files
committed
Add first class option catamorphism
1 parent cab3299 commit 7c2605e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,18 @@ public static <T> F<T, Option<T>> fromNull() {
688688
return Option::fromNull;
689689
}
690690

691+
/**
692+
* First-class catamorphism for Option: return a function that will performs
693+
* a reduction on an optional value using the given arguments.
694+
*
695+
* @param none The value to return if this optional value has no value.
696+
* @param some The function to apply to the value of this optional value.
697+
* @return the reducing function.
698+
*/
699+
public static final <A, B> F<Option<A>, B> cata(final B none, final F<A, B> some) {
700+
return o -> o.option(none, some);
701+
}
702+
691703
/**
692704
* Joins the given optional value of optional value using a bind operation.
693705
*

0 commit comments

Comments
 (0)