How to convert a 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 / easy) way to convert Range to SortedSet ?

+4
source share
1 answer

What could be easier than that? (You do not need a type parameter or extra brackets.)

 SortedSet(0 to 9:_*) 

It should also be quite effective.

+15
source

Source: https://habr.com/ru/post/1383305/


All Articles