I'm looking for something like the immutable SortedSet, except I want elements to be ordered in the sequence they were passed into the constructor.
UniqueList(4,2,3,1,1) // Throws exception
UniqueList(4,2,3,1) // Iterator yields: 4,2,3,1
Try collection.mutable.LinkedHashSet - it has unique elements and traversal occurs in the order that the elements were added.
There's ListSet, although it will have the values in the reverse order that they were passed into the constructor.
scala> import scala.collection.immutable.ListSet
import scala.collection.immutable.ListSet
scala> ListSet(1,2,3,4)
res7: scala.collection.immutable.ListSet[Int] = ListSet(4, 3, 2, 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With