e.g. `() -> Unit` is `Function0<Unit>`
# announcements
t
e.g.
() -> Unit
is
Function0<Unit>
k
It's not that clear what you want, are you looking for currying?
t
@karelpeeters no, I’m trying to avoid using
()
k
What does that mean? Why?
t
because I want to know what the actual type, like
() -> Unit
is
Function0<Unit>
k
Ah okay, now I get it. That would be
Function1<LiveNavigator, Unit>
.
You can check things like this easily using Show Kotlin Bytecode and then Decompile.
t
the Decompiler didn’t show the generic part, it is in the metadata which I couldn’t understand sadly
I believe
Function1<LiveNavigator, Unit>
is
(LiveNavigator) -> Unit
not
LiveNavigator.() -> Unit
or I’m wrong? maybe?
k
They're the same thing behind the scenes.
And even in the language itself, you can just pass a
(X) -> Unit
to something that expects a
X.() -> Unit
and the other way around, in the end it's all syntax sugar.
t
pretty sure
(LiveNavigator) -> Unit
will make
LiveNavigator
as
it
while
LiveNavigator.() -> Unit
make
LiveNavigator
as
this
. I have seen a lamba have both
it
and
this
as the same time (maybe something like LiveNavigator.(Int) -> Unit)
k
Indeed, but in the end
it
vs
this
is just a name, there's no actual
this
object that the function is being invoked on. This is what I mean by "syntax sugar". The second example function then becomes
Function2<LineNavigator, Int, Unit>
.
t
but when declare a
Function2<LineNavigator, Int, Unit>
I don’t get
this
as
LineNavigator
and
it
as
Int
(but get
lamba { navigator, value -> } instead
) how can I do this?
k
I don't think you can do that, just use the standard
() -> Unit
notation instead. Why do you want to avoid it?
t
Because I want things to be explicit
It turn out you be be explicit with
(LiveNavigator) -> Unit
but not with
LiveNavigator.() -> Unit
k
What? How is
Function1<X, Y>
more explicit then
(X) -> Y
? The latter is way more readable.
Just look at the
Function1
interface as an implementation detail you shouldn't worry about.