MapSet
A set of functions for working with sets.
The MapSet
is represented internally as a struct, therefore %MapSet{}
can be used whenever there is a need to match on any MapSet
. Note though the struct fields are private and must not be accessed directly. Instead, use the functions in this module.
Summary
Types
Functions
- delete(set, value)
-
Deletes
value
fromset
- difference(map_set1, map_set2)
-
Returns a set that is
set1
without the members ofset2
- disjoint?(map_set1, map_set2)
-
Checks if
set1
andset2
have no members in common - equal?(map_set1, map_set2)
-
Checks if two sets are equal
- intersection(map_set1, map_set2)
-
Returns a set containing only members that
set1
andset2
have in common - member?(map_set, value)
-
Checks if
set
containsvalue
- new()
-
Returns a new set
- new(mapset)
-
Creates a set from an enumerable
- new(enumerable, transform)
-
Creates a mapset from an enumerable via the transformation function
- put(set, value)
-
Inserts
value
intoset
ifset
doesn’t already contain it - size(map_set)
-
Returns the number of elements in
set
- subset?(map_set1, map_set2)
-
Checks if
set1
’s members are all contained inset2
- to_list(map_set)
-
Converts
set
to a list - union(map_set1, map_set2)
-
Returns a set containing all members of
set1
andset2
Types
t()
t
value()
value() :: term
Functions
delete(set, value)
delete(t, value) :: t
Deletes value
from set
.
Returns a new set which is a copy of set
but without value
.
Examples
iex> set = MapSet.new([1, 2, 3]) iex> MapSet.delete(set, 4) #MapSet<[1, 2, 3]> iex> MapSet.delete(set, 2) #MapSet<[1, 3]>
difference(map_set1, map_set2)
difference(t, t) :: t
Returns a set that is set1
without the members of set2
.
Examples
iex> MapSet.difference(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[1]>
disjoint?(map_set1, map_set2)
disjoint?(t, t) :: boolean
Checks if set1
and set2
have no members in common.
Examples
iex> MapSet.disjoint?(MapSet.new([1, 2]), MapSet.new([3, 4])) true iex> MapSet.disjoint?(MapSet.new([1, 2]), MapSet.new([2, 3])) false
equal?(map_set1, map_set2)
equal?(t, t) :: boolean
Checks if two sets are equal.
The comparison between elements must be done using ===
.
Examples
iex> MapSet.equal?(MapSet.new([1, 2]), MapSet.new([2, 1, 1])) true iex> MapSet.equal?(MapSet.new([1, 2]), MapSet.new([3, 4])) false
intersection(map_set1, map_set2)
intersection(t, t) :: t
Returns a set containing only members that set1
and set2
have in common.
Examples
iex> MapSet.intersection(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[2]> iex> MapSet.intersection(MapSet.new([1, 2]), MapSet.new([3, 4])) #MapSet<[]>
member?(map_set, value)
member?(t, value) :: boolean
Checks if set
contains value
.
Examples
iex> MapSet.member?(MapSet.new([1, 2, 3]), 2) true iex> MapSet.member?(MapSet.new([1, 2, 3]), 4) false
new()
new() :: t
Returns a new set.
Examples
iex> MapSet.new #MapSet<[]>
new(mapset)
new(Enum.t) :: t
Creates a set from an enumerable.
Examples
iex> MapSet.new([:b, :a, 3]) #MapSet<[3, :a, :b]> iex> MapSet.new([3, 3, 3, 2, 2, 1]) #MapSet<[1, 2, 3]>
new(enumerable, transform)
new(Enum.t, (term -> term)) :: t
Creates a mapset from an enumerable via the transformation function.
Examples
iex> MapSet.new([1, 2, 1], fn x -> 2 * x end) #MapSet<[2, 4]>
put(set, value)
put(t, value) :: t
Inserts value
into set
if set
doesn’t already contain it.
Examples
iex> MapSet.put(MapSet.new([1, 2, 3]), 3) #MapSet<[1, 2, 3]> iex> MapSet.put(MapSet.new([1, 2, 3]), 4) #MapSet<[1, 2, 3, 4]>
size(map_set)
size(t) :: non_neg_integer
Returns the number of elements in set
.
Examples
iex> MapSet.size(MapSet.new([1, 2, 3])) 3
subset?(map_set1, map_set2)
subset?(t, t) :: boolean
Checks if set1
’s members are all contained in set2
.
This function checks if set1
is a subset of set2
.
Examples
iex> MapSet.subset?(MapSet.new([1, 2]), MapSet.new([1, 2, 3])) true iex> MapSet.subset?(MapSet.new([1, 2, 3]), MapSet.new([1, 2])) false
to_list(map_set)
to_list(t) :: list
Converts set
to a list.
Examples
iex> MapSet.to_list(MapSet.new([1, 2, 3])) [1, 2, 3]
union(map_set1, map_set2)
union(t, t) :: t
Returns a set containing all members of set1
and set2
.
Examples
iex> MapSet.union(MapSet.new([1, 2]), MapSet.new([2, 3, 4])) #MapSet<[1, 2, 3, 4]>
© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/elixir/1.3.4/MapSet.html