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 AMdiesieben07
06/14/2017, 11:42 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)janvladimirmostert
06/14/2017, 11:57 AMelizarov
06/14/2017, 11:59 AMelizarov
06/14/2017, 12:00 PM1..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 negativeelizarov
06/14/2017, 12:01 PMjanvladimirmostert
06/14/2017, 12:01 PM1..-2 in there, you would expect a list [1, 0, -1, -2]janvladimirmostert
06/14/2017, 12:02 PMjanvladimirmostert
06/14/2017, 12:02 PMelizarov
06/14/2017, 12:03 PMn times, then you expect (1..n).forEach { ... } to be not doing anything when n == 0elizarov
06/14/2017, 12:04 PMn < 0.elizarov
06/14/2017, 12:04 PMjanvladimirmostert
06/14/2017, 12:05 PMelizarov
06/14/2017, 12:06 PMelizarov
06/14/2017, 12:06 PMjanvladimirmostert
06/14/2017, 12:06 PMelizarov
06/14/2017, 12:08 PMrangeTo operator)elizarov
06/14/2017, 12:09 PMrangeTo is also Ok.janvladimirmostert
06/14/2017, 12:11 PMjanvladimirmostert
06/14/2017, 12:12 PMpyRangeTo is probably good enough, makes code more readableelizarov
06/14/2017, 12:13 PMjanvladimirmostert
06/14/2017, 12:14 PMjanvladimirmostert
06/14/2017, 12:17 PM