I'd like to reference a partially-applied function...
# functional
u
I'd like to reference a partially-applied function with receiver. Is this possible? Say, I have a function
f(x: X, (X) -> Y): Y
that takes some argument
x: X
and a function
(X) -> Y
. And I have a concrete function with receiver, say
Int.makeY(x: X): Y
. I would like to partially apply
makeY
to a given receiver and pass it to
f
, like
Copy code
val foo = 5
f(x) { foo::makeY }
However, this results in an ArgumentTypeMismatch compilation error, stating that
Y
was expected instead of the provided function reference. Am I simply making a mistake in my declaration, or is it simply not possible to pass a partially applied function with receiver as reference?
e
I think you’re currently passing
() -> (X) -> Y
by passing the reference inside a lambda. Does it work with
f(x, foo::makeY)?
u
that's the solution, thanks a lot!