ExBitset (ex_bitset v1.1.1) View Source
ExBitset provides the functionality to create/query bitarray sets.
To define a set constructor you first need to specify all possible set elements. This is done via the defbitset macro:
defmodule Roles
import ExBitset, only: [defbitset: 1]
defbitset [:admin, :owner, :writer, :viewer, :guest]
endThen, create a new set specifying all of the elements in it:
roles = ExBitset.new(Roles, [:admin, :owner])To then query the set, you can use any of the following functions:
ExBitset.member?(roles, :owner) # => true
roles2 = ExBitset.new(Roles, [:admin, :writer])
ExBitset.union(roles, roles2) |> Enum.to_list() # => [:admin, :owner, :writer]
ExBitset.intersection(roles, roles2) |> Enum.to_list() # => [:admin]
ExBitset.subtract(role, roles2) |> Enum.to_list() # => [:owner]
# OR alternatively using Enum functions
Enum.join(roles, ", ") # => "admin, owner"
Enum.map(roles, &to_string/1) # => ["admin", "owner"]
Link to this section Summary
Link to this section Types
Specs
item() :: term()
Specs
t()
Link to this section Functions
Specs
count(t()) :: non_neg_integer()
Specs
Specs
Specs
from_int(module(), non_neg_integer()) :: t()
Specs
Specs
Specs
Specs
Specs
Specs
to_int(t()) :: non_neg_integer()