I’m curious; how have people liked the `it` featur...
# announcements
r
I’m curious; how have people liked the
it
feature of Kotlin? Does it cause problems/confusions?
t
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
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
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
Is
it
equivalent to
_
in Scala?
k
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
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
You can, but what if you want to do
myObject.map { it.foo?.bar }
, or something more complex?
b
So just like in Scala, where you’d wrote:
strings.map( _.length )
k
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