Multiset
This is an implementation of multisets for Elixir. Multisets are sets allowing multiple instances of values.
Documentation: http://hexdocs.pm/multiset.
Usage
Add this library to your list of dependencies in mix.exs:
def deps do
[{:multiset, "~> 0.0.4"}]
end
Then run mix deps.get in your shell to fetch and compile multiset.
Examples
Start an interactive Elixir shell with iex -S mix.
iex> Multiset.new([1, 2, 1, 3])
#Multiset<[{1, 2}, {2, 1}, {3, 1}]>
iex> multiset1 = ~w(to be or not to be)a |> Multiset.new
#Multiset<[be: 2, not: 1, or: 1, to: 2]>
iex> Multiset.values(multiset1)
#MapSet<[:be, :not, :or, :to]>
iex> Multiset.multiplicity(multiset1, :be)
2
iex> Multiset.multiplicity(multiset1, :or)
1
iex> multiset2 = ~w(neither a borrower nor a lender be)a |> Multiset.new
#Multiset<[a: 2, be: 1, borrower: 1, lender: 1, neither: 1, nor: 1]>
iex> Multiset.intersection(multiset1, multiset2)
#Multiset<[be: 1]>
iex> Multiset.union(multiset1, multiset2)
#Multiset<[a: 2, be: 2, borrower: 1, lender: 1, neither: 1, nor: 1, not: 1, or: 1, to: 2]>
iex> Multiset.sum(multiset1, multiset2)
#Multiset<[a: 2, be: 3, borrower: 1, lender: 1, neither: 1, nor: 1, not: 1, or: 1, to: 2]>See the documentation for more available functionality.