Currying: Difference between revisions
Content added Content deleted
m (→{{header|AppleScript}}: Updated primitive) |
|||
Line 597: | Line 597: | ||
} |
} |
||
}</lang> |
}</lang> |
||
Or in Java 8: |
|||
<lang java8> |
|||
import java.util.function.BiFunction; |
|||
import java.util.function.Function; |
|||
public class Curry { |
|||
public static <T, U, R> Function<T, Function<U, R>> curry(BiFunction<T, U, R> biFunction) { |
|||
return t -> u -> biFunction.apply(t, u); |
|||
} |
|||
public static int add(int x, int y) { |
|||
return x + y; |
|||
} |
|||
public static void main(String[] args) { |
|||
BiFunction<Integer, Integer, Integer> bif = Curry::add; |
|||
Function<Integer, Function<Integer, Integer>> curried = curry(bif); |
|||
Function<Integer, Integer> add5 = curried.apply(5); |
|||
System.out.println(add5.apply(2)); |
|||
} |
|||
} |
|||
</lang> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |