Skip to content

Instantly share code, notes, and snippets.

@grudus
Created October 24, 2017 09:29
Show Gist options
  • Save grudus/fcc2ecef36d35cae92375fe0e150e913 to your computer and use it in GitHub Desktop.
Save grudus/fcc2ecef36d35cae92375fe0e150e913 to your computer and use it in GitHub Desktop.
public class Curry3 {
public static <A, B, C, X> Function<A, Function<B, Function<C, X>>> curry3(TriFunction<A, B, C, X> f) {
return a -> b -> c -> f.apply(a, b, c);
}
public static <A, B, C, X> TriFunction<A, B, C, X> unCurry3(Function<A, Function<B, Function<C, X>>> f) {
return (a, b, c) -> f.apply(a).apply(b).apply(c);
}
//example
public static void main(String[] args) {
TriFunction<Integer, Integer, Integer, Integer> xx = (a, b, c) -> a + b + c;
xx.apply(1,2,3); //6
curry3(xx).apply(1).apply(2).apply(3); //6
uncurry3(curry3(add)).apply(1,2,3); //6
}
}
@FunctionalInterface
interface TriFunction<A, B, C, X> {
X apply (A a, B b, C c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment