Curry/uncurry in Java
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
public class Currying { | |
// Suppress default constructor for non-instantiability | |
private Currying() { | |
throw new AssertionError(); | |
} | |
public static <T, U, R> Function<T, Function<U, R>> curry( | |
BiFunction<? super T, ? super U, ? extends R> bf) { | |
return t -> u -> bf.apply(t, u); | |
} | |
public static <T, U, R> BiFunction<T, U, R> uncurry( | |
Function<? super T, ? extends Function<? super U, ? extends R>> f) { | |
return (t, u) -> f.apply(t).apply(u); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment