https://kotlinlang.org logo
Title
r

rattrayalex

06/07/2017, 4:47 PM
I’m curious; how have people liked the
it
feature of Kotlin? Does it cause problems/confusions?
t

tipsy

06/07/2017, 5:10 PM
rattrayalex: i love it, so do people i've asked to review. most people don't understand it initially, but it only takes a few seconds to explain
👍 1
h

hetang

06/07/2017, 5:13 PM
I like it too. But there are few gotchas in it, if you using nested
.let
blocks then you should be careful to use it. For that case we are using unwrap library: https://github.com/importre/kotlin-unwrap
k

kevinmost

06/07/2017, 5:26 PM
it
is great if you use it properly. Don't use it in nested or multi-line lambdas. It should only be used when the definition of
it
is immediately and unambiguously clear
b

bartektartanus

06/07/2017, 5:50 PM
Is
it
equivalent to
_
in Scala?
k

kevinmost

06/07/2017, 6:26 PM
No,
_
is equivalent to
_
in Scala 😆 . If you have a lambda with one parameter, you can choose not to define the param name and it's implicitly named
it
so you can do
strings.map { string -> string.length }
, or you could do
strings.map { it.length }
both forms are equivalent
c

chb0kotlin

06/07/2017, 10:14 PM
I thought you can do functional references in kotlin like in java with
map(SomeClass::transformThing)
that sytax obviates the need for a known symbol in a lambda
k

kevinmost

06/07/2017, 10:23 PM
You can, but what if you want to do
myObject.map { it.foo?.bar }
, or something more complex?
b

bartektartanus

06/08/2017, 5:41 AM
So just like in Scala, where you’d wrote:
strings.map( _.length )
k

kevinmost

06/08/2017, 10:35 AM
oh wow, didn't realize
_
meant so many things in Scala https://stackoverflow.com/a/8001065/3204764
I was thinking of the unused parameter use-case