Scala tip: Easily create lists of test data with Ranges in Scala

If you ever need a list/sequence when testing some Scala code, don’t forget this simple technique:

scala> val l = (1 to 10).toList
l: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

Of course you can do many other things to your list if you want, such as multiplying each element by 2, like this:

scala> val l = (1 to 10).map(_ * 2).toList
l: List[Int] = List(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)

You can do this with characters as well:

scala> val l = ('a' to 'k').toList
l: List[Char] = List(a, b, c, d, e, f, g, h, i, j, k)