Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Range to SortedSet in Scala?

If I want to convert Range to Set I can write

(0 to 9).toSet

What if I need to convert Range to SortedSet? I can write something like:

scala.collection.immutable.SortedSet[Int]((0 to 9): _*)
scala.collection.immutable.SortedSet[Int]() ++ (1 to 9)

Does it make sense? Is there any "better" (efficient/simple) way to convert Range to SortedSet?

like image 518
Michael Avatar asked Nov 27 '11 14:11

Michael


1 Answers

What could possibly be more simple than this? (You don't need the type parameter or the extra parentheses.)

SortedSet(0 to 9:_*)

It should also be reasonably efficient.

like image 162
Kim Stebel Avatar answered Nov 05 '22 11:11

Kim Stebel