Olaf Gottschalk
12/01/2024, 5:35 AMmap
the order of completion suggestions looks like in the first image.
The .map { ... }
is the very first one - which is good and "correct". Hit Tab and directly type your lambda code!
When K2 mode is enabled though, the list looks a lot different... 😔 (second picture)
The .map(transform: (Int)->R)
comes right before the more common and useful .map { ... }
completion! I fell into the trap to hit Tab and see myself with this not very welcoming completion as when typing code you probably did not yet write your own mapping function, but rather need a quick lambda!
But there is a second problem waiting for you. Once you select the "right" completion by hitting Down, then Tab, you see that the completion now wants you to give it
a real name! In K1, you could simply type your lambda like .map { it * 2 }
without bothering to already know a name! In K2 mode, though, it completes with .map { i -> }
with i
highlighted. I do not need, not want this at this point in time! It is just distracting my typing and coding flow. Renaming it
is fine when done later, once you see the resulting code. Never would I want an .map { i -> i * 2}
as my very first code. That's the whole point in Kotlin being cool with it
! Lambdas should be short and concise and not full of boilerplate!
These findings seem to be true for many or even all collection methods like map
, sumOf
, count
, .....
It is such tiny details that instantly let me throw away K2 mode. 😞 Unless, that is, I am too blind and this can be configured...
Can it? Thanks!bod
12/01/2024, 7:51 AM