Logo

Programming-Idioms

  • Haskell
  • Scala

Idiom #118 List to set

Create the set y from the list x.
x may contain duplicates. y is unordered and has no repeated values.

Turning the list [a,b,c,b] into the set {c,a,b}
val y = x.toSet

The default implementation of Set is a HashSet
import qualified Data.Set as Set
y = Set.fromList x
(def y (set x))

New implementation...