how to fix the second parameter of a function with vavr?

104 views Asked by At

Suppose I have a function which takes two parameter.

Function2<T1,T2,R> function;

I want to fix the second parameter and makes it a Function1<T1,R>.

With Function2.apply(T1 t), I can only fix the first parameter, is there a way to fix the second parameter?

2

There are 2 answers

0
Nándor Előd Fekete On BEST ANSWER

There's no utility function built into vavr that does a partial application of the second argument. The available utility functions only do partial application for the first argument.

You can easily do the partial application yourself, but you'll need to do that within your own codebase.

static <T1, T2, R> Function1<T1, R> partialApply2(Function2<T1, T2, R> f, T2 p2) {
    return p1 -> f.apply(p1, p2);
}
2
JonR85 On

In Java, a method signature is part of the method declaration. It's the combination of the method name and the parameter list.

https://www.thoughtco.com/method-signature-2034235