MapSet is an Elixir collection for unique values of any type. It provides a higher-level set abstraction on top of built-in data structures and is implemented in pure Elixir. section 2.4.11 section 4.1
Use the module functions as the abstraction boundary:
- Create a set with MapSet.new/0 or MapSet.new/1. section 4.1
- Check membership with MapSet.member?/2. section 2.4.11
- Add values with MapSet.put/2; the resulting set is passed into the next operation. section 2.4.11
- Chain operations with the pipe operator because MapSet functions take the set first. section 4.1
- Enumerate a set with Enum functions when iteration is required. section 2.4.11
A set of days
days = MapSet.new([:monday, :tuesday, :wednesday]) MapSet.member?(days, :monday) # true days = MapSet.put(days, :thursday) Enum.each(days, &IO.puts/1) section 2.4.11
iex(1)> days =
MapSet.new() |> #1
MapSet.put(:monday) |> #2
MapSet.put(:tuesday) #2
iex(2)> MapSet.member?(days, :monday) #3
true
Follow the pipe-based construction of a MapSet and test membership against the resulting abstraction. section 4.1
