Skip to content

Commit 4351092

Browse files
committed
add an uncurried version of Function.apply for better perf.
1 parent d1f24b3 commit 4351092

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/src/main/java/fj/Function.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,18 @@ public static <A, B, C> F<C, B> bind(final F<C, A> ma, final F<A, F<C, B>> f) {
718718
* @return A new function after applying the given higher-order function to the given function.
719719
*/
720720
public static <A, B, C> F<C, B> apply(final F<C, F<A, B>> cab, final F<C, A> ca) {
721-
return bind(cab, f -> compose(f, ca));
721+
return apply(uncurryF2(cab), ca);
722+
}
723+
724+
/**
725+
* Performs function application within a higher-order function (applicative functor pattern).
726+
*
727+
* @param cab The higher-order function to apply a function to.
728+
* @param ca A function to apply within a higher-order function.
729+
* @return A new function after applying the given higher-order function to the given function.
730+
*/
731+
public static <A, B, C> F<C, B> apply(final F2<C, A, B> cab, final F<C, A> ca) {
732+
return c -> cab.f(c, ca.f(c));
722733
}
723734

724735
/**

0 commit comments

Comments
 (0)