Tom Adam
06/03/2019, 5:11 PM(5 downTo 3 step 3).forEach { println(it) }
or
(5 downTo 3).filter { it % 2 == 0}
.forEach { println(it) }
However, if filter would be infix, one could also write
(5 downTo 3 filter { it % 2 == 0})
.forEach { println(it) }
which would be totally in sync with the infix syntax of step, and possibly would mean a more consistent API. Any thoughts?Tom Adam
06/04/2019, 6:52 AMelizarov
06/04/2019, 10:09 AMhho
06/04/2019, 10:47 AMfilter as a more general construct. It works on collections, sequences, streams etc.
step on the other hand is specific to progressions, that's probably why it has an infix version – to enable the use like in your first example.Tom Adam
06/04/2019, 11:49 AMelizarov
06/04/2019, 2:17 PMilya.gorbunov
06/04/2019, 2:46 PMinfix modifier in Kotlin and every function with a receiver and one parameter was eligible to be called as infix.
Then we decided we want make these things explicit and require that modifier to designate a function being callable in the infix form. That raised a question which of the standard functions should remain callable as infix.
For the functions like filter, map, and so on, we concluded it would be more consistent to invoke them always with a dot, rather than to allow both call forms and burden users with a decision which one to use in their particular case.LeoColman
06/04/2019, 3:38 PMilya.gorbunov
06/04/2019, 6:29 PMLeoColman
06/04/2019, 6:31 PM