All posts

Understanding Elixir MapSet

This and the other “Deck” posts are a repurposing of flashcard study decks to Q&A blog posts. Google was not showing love to this content as a set of flashcards and I didn’t want to delete them entirely, I hope you find it useful.

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?

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

How do you create a MapSet?

Using 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<[]> 
=> MapSet.put(ms, "new_value") 

How do you remove a value in a MapSet?

Using Mapset.delete/2

=> ms = 
=> 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