Consumer with more than one argument in Java 8?

java-8, java-stream, lambda

Solution

For 3 and more arguments you could use curried(http://en.wikipedia.org/wiki/Currying) functions with last consumer:

Function<Double, Function<Integer, Consumer<String>>> f = d -> i -> s -> {
            System.out.println("" + d+ ";" + i+ ";" + s); 
        };
f.apply(1.0).apply(2).accept("s");

Output is:

1.0;2;s

It's enough to have a function of one argument to express function of any number of arguments: https://en.wikipedia.org/wiki/Currying#Lambda_calculi

Problem

Such as in .Net, which provides several implementations of the `Action` delegate (equivalent to Java `Consumer` functional interface) with different number and type of arguments, I was expecting that Java 8 provides some way of specifying a `Consumer` with more than one argument of different types. I know that in Java we cannot define different types with the same name that just differ in the generic type parameters, but there would be nice fluent alternatives to provide a multi-argument `Consumer`. Is there any easy way to do it, which does not require defining a new functional interface?

Original source