Java: (awful, to read and write)
import java.util.function.Function;
public class Main {
public static void main(String[] args) {
Function<Integer, Function<Integer, Integer>> add = x -> y -> x + y;
Function<Integer, Integer> addFive = add.apply(5);
int result = addFive.apply(3); // Output will be 8
}
Ruby a. (still not great, but there's many ways to do it!) add = proc { |x, y| x + y }
curried_add = add.curry
add_five = curried_add.call(5)
result = add_five.call(3)
}
Ruby b. (slightly more concise) add = ->(x) { ->(y) { x + y } }
add_five = add.(5)
result = add_five.(3)
Elixir (functional programing lang but doesn't lean on currying too much) add = fn x -> (fn y -> x + y end) end
add_five = add.(5)
result = add_five.(3)
ES6 (say what you want about javascript but they at least did arrow functions right) const add = x => y => x + y;
const addFive = add(5);
const result = addFive(3);
Standard ML (clearly a lang where currying is a first class concern in its language design) fun add x y = x + y;
val addFive = add 5;
val result = addFive 3;
and finally Haskell (which, in this case is a joy to read and write.) add x y = x + y
addFive = add 5
result = addFive 3