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]> |
Get Programming Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.