although I suppose it's quite unlikely that you'd be using this on a lambda expression, as that would be fairly pointless
g
gsala
12/02/2022, 8:59 AM
Thanks.
My use case is I have a container class
Copy code
class Container(
val container : ContainerModel,
val onItemClick : (Container, Item -> Unit)
) {
val items = container.items
.map { Item(it, onItemClick.partialApply(container) }
}
and an item class
Copy code
class Item(
val item : ItemModel,
val onItemClick : (Item -> Unit)
)
So I want to provide the container parameter to the lambda passed into the items
gsala
12/02/2022, 9:11 AM
Now I don’t really know if I should turn the extension function above into an operator invoke function
a
andyg
12/02/2022, 9:19 AM
I would likely take Roman's advice and avoid, but in any case, I think this is known as "currying"
t
Ties
12/02/2022, 12:03 PM
Yes, the concept is called partial application. Currying is turning a function with 2 (or more) arguments into 2 functions with 1 argument (e.g: plus(a,b) becomes plus(a)(b), where plus(a) returns a function with 1 argument where a is partially applied