janvladimirmostert
06/14/2017, 11:39 AM1..4
return you a list, but 4..1
doesn’t return anything. One would expect 4..1
equals (1..4).reversed()
.diesieben07
06/14/2017, 11:41 AMjanvladimirmostert
06/14/2017, 11:43 AMdiesieben07
06/14/2017, 11:43 AMjanvladimirmostert
06/14/2017, 11:45 AMholgerbrandl
06/14/2017, 11:48 AMbase::seq(5,1)
gives a descending sequence, so I’d think not everyone is expecting an ascending sequence. I would not either. I agree with @janvladimirmostert about the expected behavior.diesieben07
06/14/2017, 11:49 AMelizarov
06/14/2017, 11:54 AM..
or rangeTo
) or descending (downTo
) sequence. More here: https://kotlinlang.org/docs/reference/ranges.htmlholgerbrandl
06/14/2017, 11:56 AMcreates a range from this value to the specified other value
, so if this
is greater than other
the resulting sequence should start with this
to fulfill its contract.janvladimirmostert
06/14/2017, 11:57 AMoperator fun Any.rangeTo(b: Any) = if (this > b) getAscendingRange(a,b) else getDescendingRange(a,b)
elizarov
06/14/2017, 11:59 AM1..i
in your code you usually know it has to be ascending and you don’t want it to do anything when i
is zero or negativejanvladimirmostert
06/14/2017, 12:01 PM1..-2
in there, you would expect a list [1, 0, -1, -2]
elizarov
06/14/2017, 12:03 PMn
times, then you expect (1..n).forEach { ... }
to be not doing anything when n == 0
n < 0
.janvladimirmostert
06/14/2017, 12:05 PMelizarov
06/14/2017, 12:06 PMjanvladimirmostert
06/14/2017, 12:06 PMelizarov
06/14/2017, 12:08 PMrangeTo
operator)rangeTo
is also Ok.janvladimirmostert
06/14/2017, 12:11 PMpyRangeTo
is probably good enough, makes code more readableelizarov
06/14/2017, 12:13 PMjanvladimirmostert
06/14/2017, 12:14 PM