Understanding Elixir MapSet

This and the other “Deck” posts are a repurposing of flashcard study decks to Q&A blog posts.

What is a MapSet?

A `MapSet` is a `Set`. Sets are data structures that can contain unique elements of any kind.

How does a MapSet differ from a Map?

A `Map` is an associative data structure where a `MapSet` is not.

Can a MapSet contain duplicate values?

No. If a duplicate value is provided to a `MapSet` it will result in a no-op.

When do you use a MapSet?

`MapSet`s are really fast data structures and are often used when in need of optimum search performance.

How do you create a MapSet?

Using `MapSet.new/0`. All data must be added to the `MapSet` after it is constructed.

How do you add a value to a MapSet?

Using `Mapset.put/2` ``` => ms = MapSet.new() #MapSet<[]> => MapSet.put(ms, "new_value") #MapSet<["new_value"]> ```

How do you remove a value in a MapSet?

Using `Mapset.delete/2` ``` => ms = MapSet.new() => MapSet.put(ms, "new_value") => MapSet.delete(ms, "new_value") ```

How do you iterate a MapSet?

A `MapSet` is an Elixir Enumerable. Like other Enumerables you can use the `Enum` module to iterate the collection ex `Enum.map/2`