Logo

Programming-Idioms

  • Smalltalk
  • Elixir

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}
y = MapSet.new(x)
y = x |> Enum.uniq |> List.to_tuple

Remove list duplication and convert to a tuple.

Warning: a tuple is not really a set.
y := x asSet
(def y (set x))

New implementation...