I have a list of `() -> Item` lambdas and I wa...
# stdlib
m
I have a list of
() -> Item
lambdas and I want to map it like
map { it() }
. Is it possible to write this using a function reference? I was guessing something like
map((()->Item)::invoke)
a
how about this?
👍 1
m
Thanks! Got me thinking that a typealias might also work, and it does:
Copy code
private typealias ItemSupplier = () -> Item
val items = list.map(ItemSupplier::invoke)
👍 2
s
What a hack 😂
e
Function0<Item>::invoke
👍 2
m
@ephemient good to know, thanks. Though it’s good to know a typealias/interface is not needed, I’m thinking using a typealias is a little clearer. Perhaps generally whenever a lambda is used as a generic.
👍 1