This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.25, “How to Populate a Scala Collection with a Range”
Problem
You want to populate a List
, Array
, Vector
, or other sequence with a Range
.
Solution
Call the range
method on sequences that support it, or create a Range
and convert it to the desired sequence.