https://kotlinlang.org logo
Title
p

prabello

10/31/2018, 11:57 AM
i tried doing
let{::loveThePet}
but the return end up beign different and could not chain the calls, they were returning a KFunction instead of the result
s

Shawn

10/31/2018, 3:55 PM
{::loveThePet}
is a lambda that returns a reference to
loveThePet
let(::loveThePet)
invokes
let
on the receiver object using
loveThePet
as the function parameter
they are very different expressions
let{::loveThePet}
would be equivalent to
let({ ::loveThePet })
or
val func = { ::loveThePet }
item.let(func)
What you’d be doing, in essence, is passing to
.let()
a lambda that discards its arguments and simply returns that method reference, which is why you get a signature error and end up with a transform that leaves you with a
KFunction
the requisite expression would therefore look more like this
returnHuman("name")
    .let(::saveAHumanReturningABall)
    .let(::kickTheBallReturningABall)
    .let(::keepTheBallReturnAPet)
    .let(::loveThePet)
assuming those functions are member declarations and not just local variables
if they are just local variables, the
::
is not needed to qualify based on namespace