Is there something like `Function1` but as consume...
# announcements
v
Is there something like
Function1
but as consumer, so without return value?
y
A
Function1<T, Unit>
should do the job just fine. Or alternatively if you need a proper interface use a
fun interface Consumer<T> { fun consume(t: T): Unit }
3
v
Ah, thanks, the
Function1<T, Unit>
was exactly what I needed
r
Why not just
(T) -> Unit
?
l
I think you want
Function0
, or just use the functional type (you can implement it like an interface).
v
Function0
would give me 0 parameters and 0 or 1 return type, but I needed 1 parameter and 0 return type, so
Function1<T, Unit>
was exactly what I needed.
(T) -> Unit
didn't work because I needed it as generic type argument like
object : TypeOf<Function1<T, Unit>>() {}
y
@Vampire hate to be the um actually guy, but AFAIK
object : TypeOf<(T) -> Unit>() {}
would still work just fine
1
v
Hm, strange, I was sure I tried that and it didn't work but works now. Probably some typo I had, thanks.
👍 1