When it comes to iteration and ranges one can writ...
# stdlib
t
When it comes to iteration and ranges one can write something like:
Copy code
(5 downTo 3  step 3).forEach { println(it) }
or
Copy code
(5 downTo 3).filter { it % 2 == 0}
        .forEach { println(it) }
However, if filter would be infix, one could also write
Copy code
(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?
3
1
Well, that was a nice discussion with good arguments, @elizarov.:)
1
1
e
I don’t have any arguments for this discussion, sorry.
h
I see
filter
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.
t
@hho That is a good point and argument. I think, discussing things is always a better approach than just using power. At least this is the way we work in Norway. I know, that countries and cultures differ.
🤦‍♂️ 2
e
Sorry, I did not mean to use power. I wanted to express my opinion (dislike of the idea) while lacking arguments to explain what exactly I did not like.
👍 1
i
There was a time when there was no
infix
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.
2
l
@ilya.gorbunov why was the decision to take off default infix behavior and add the keyward taken?
i
👍 1
l
thanks!