Skip to content

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

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?


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);