Open
Description
reproduction steps
using Scala 3,
scala> (1 to 26).reverse
val res0: Range = Range 26 to 1 by -1
scala> ('a' to 'z').reverse
val res1: scala.collection.immutable.NumericRange[Char] = empty NumericRange z to a by �
problem
Seems like all other Ranges give you a collection back of the same size when you reverse
them, but a Range of Chars returns an empty Range. I understand you can get around this by turning it into a Seq (with memory usage implications) or using reverseIterator
, but the above behaviour was surprising and caused a bug in my code.
Similarly it would be nice if you could make a reversed range with ('z' to 'a' by -1)
or something to that effect. (Interestingly, this won't compile with a negative number, saying it needs to be a Char, but does with a positive number... 🤷)