O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sets

There is currently just one implementation of sets, the HashSet.

 
iex>​ set1 = Enum.into 1..5, HashSet.new
 
#HashSet<[1, 2, 3, 4, 5]>​​​
 
iex>​ Set.member? set1, 3
 
true​​​
 
iex>​ set2 = Enum.into 3..8, HashSet.new
 
#HashSet<[3, 4, 5, 6, 7, 8]>​​​
 
iex>​ Set.union set1, set2
 
#HashSet<[7, 6, 4, 1, 8, 2, 3, 5]>​​​
 
iex>​ Set.difference set1, set2
 
#HashSet<[1, 2]>​​​
 
iex>​ Set.difference set2, set1
 
#HashSet<[6, 7, 8]>​​​
 
iex>​ Set.intersection set1, set2
 
#HashSet<[3, 4, 5]>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required