olek
08/06/2018, 7:45 AMnames.groupBy { it.length }, one could use names.groupBy(String::length), but it's kinda cumbersome in many cases, especially when chained, and it's unclear what happens when the method has arity of 1. names.groupBy(::length) would be shorter, but ::length is evaluated in the current lexical scope. How about something like names.groupBy(.length)? Scala has names.groupBy(_.length), Ruby has `Symbol#to_proc`: names.group_by(&:length). What do you guys think?voddan
08/06/2018, 7:55 AMit, or even only one when compare to _.length?olek
08/06/2018, 8:06 AM_.length would work in Kotlinolek
08/06/2018, 8:06 AMit. part and the curly bracesolek
08/06/2018, 8:06 AMolek
08/06/2018, 8:07 AMolek
08/06/2018, 8:08 AM{ it.length }, the generated bytecode needs to evaluate the lambda on every iteration, whereas with (.length) it could do some optimizationskarelpeeters
08/06/2018, 8:27 AMolek
08/06/2018, 8:45 AMolek
08/06/2018, 8:45 AM.something shorthand syntax could also be used for accessing enums, similar to Swiftkarelpeeters
08/06/2018, 8:46 AMolek
08/06/2018, 8:46 AMvoddan
08/06/2018, 9:22 AM() with {}.olek
08/06/2018, 9:29 AMAllan Wang
08/08/2018, 3:35 PMpublic inline fun <T, K> Array<out T>.groupBy(keySelector: T.() -> K) = groupBy{ it.keySelector() }
Though this naturally hinders readability and is why it wasn’t written this way in the first place.karelpeeters
08/08/2018, 3:36 PMAllan Wang
08/08/2018, 3:37 PMitAllan Wang
08/08/2018, 3:38 PMolek
08/13/2018, 6:23 PMolek
08/13/2018, 6:25 PMit