https://kotlinlang.org logo
#announcements
Title
# announcements
t

Tuan Kiet

06/15/2019, 1:27 AM
e.g.
() -> Unit
is
Function0<Unit>
k

karelpeeters

06/15/2019, 6:56 AM
It's not that clear what you want, are you looking for currying?
t

Tuan Kiet

06/15/2019, 1:18 PM
@karelpeeters no, I’m trying to avoid using
()
k

karelpeeters

06/15/2019, 1:23 PM
What does that mean? Why?
t

Tuan Kiet

06/15/2019, 1:26 PM
because I want to know what the actual type, like
() -> Unit
is
Function0<Unit>
k

karelpeeters

06/15/2019, 1:30 PM
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

Tuan Kiet

06/15/2019, 1:43 PM
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

karelpeeters

06/15/2019, 2:21 PM
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

Tuan Kiet

06/15/2019, 2:24 PM
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

karelpeeters

06/15/2019, 2:25 PM
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

Tuan Kiet

06/16/2019, 12:00 AM
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

karelpeeters

06/16/2019, 7:56 AM
I don't think you can do that, just use the standard
() -> Unit
notation instead. Why do you want to avoid it?
t

Tuan Kiet

06/16/2019, 8:11 AM
Because I want things to be explicit
It turn out you be be explicit with
(LiveNavigator) -> Unit
but not with
LiveNavigator.() -> Unit
k

karelpeeters

06/16/2019, 8:55 AM
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.
2 Views