How can I quickly create a List[Int] that has 1 to 100 in it?
I tried List(0 to 100), but it returns List[Range.Inclusive]
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
The code you tried is creating a list with a single element – the range. You might also be able to do
Edit
The
List(...)call takes a variable number of parameters (xs: A*). Unlike varargs in Java, even if you pass aSeqas a parameter (aRangeis aSeq), it will still treat it as the first element in the varargs parameter. The:_*says “treat this parameter as the entire varargsSeq, not just the first element”.If you read
: A*as “an (:) ‘A’ (A) repeated (*)”, you can think of:_*as “as (:) ‘something’ (_) repeated (*)”