Skip to content

Instantly share code, notes, and snippets.

@soverby
Last active May 17, 2018 11:55
Show Gist options
  • Save soverby/ae549f9b63f4a1f6cae49ce1db5a8804 to your computer and use it in GitHub Desktop.
Save soverby/ae549f9b63f4a1f6cae49ce1db5a8804 to your computer and use it in GitHub Desktop.
import java.util.Date;
import java.util.function.Function;
public class MultiParameterFunction {
// Bad
@FunctionalInterface
public interface TriFunction<T, U, V, R> {
public R customMethod(T t, U u, V v);
}
public static void main(String[] args) {
String stringParam = "Blah";
Long longParam = new Long("32.0");
Date date = new Date();
// Don't do this:
TriFunction<String, Long, Date, String> someTriFunction = (stringp, longp, datep) ->
stringp.concat(longp.toString()).concat(datep.toString());
someTriFunction.customMethod(stringParam, longParam, date);
// Do this instead. BTW this is an example of a higher order function also known as
// as the partially applied function pattern.
Function<String, Function<Long, Function<Date, String>>> betterFunction =
stringp -> longp -> datep -> stringp.concat(longp.toString()).concat(datep.toString());
betterFunction.apply(stringParam).apply(longParam).apply(date);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment