Mnemonix v0.10.0 Mnemonix.Features.Enumerable View Source

Functions that rely on enumerating over all key/value pairs within a store.

All of these functions are available on the main Mnemonix module. However, not all stores support exhaustive iteration. Consult your store’s docs for more information.

Stores that do not support enumeration will raise a Mnemonix.Features.Enumerable.Error when these functions are called. You can validate that a store is enumerable before you invoke them with enumerable?/1.

Link to this section Summary

Functions

Returns true if the store is enumerable

Checks that contents of stores store1 and store2 are equal

Returns all keys in store

Returns all key/value pairs in store as a list of two-tuples

Returns all values in store

Link to this section Functions

Link to this function enumerable?(store) View Source
enumerable?(Mnemonix.store()) :: boolean() | no_return()

Returns true if the store is enumerable.

Stores that return false will raise a Mnemonix.Features.Enumerable.Error for other functions in this module.

Examples

iex> {:ok, store} = Mnemonix.start_link(Mnemonix.Stores.ETS)
iex> Mnemonix.enumerable? store
true

iex> {:ok, store} = Mnemonix.start_link(Mnemonix.Stores.Memcachex)
iex> Mnemonix.enumerable? store
false
Link to this function equal?(store1, store2) View Source
equal?(Mnemonix.store(), Mnemonix.store()) :: boolean() | no_return()

Checks that contents of stores store1 and store2 are equal.

Two stores are considered to be equal if they contain the same keys and those keys contain the same values.

Examples

iex> Mnemonix.equal? Mnemonix.new(%{a: 1}), Mnemonix.new(%{a: 1})
true

iex> Mnemonix.equal? Mnemonix.new(%{a: 1}), Mnemonix.new(%{a: 2})
false

iex> Mnemonix.equal? Mnemonix.new(%{a: 1}), Mnemonix.new(%{b: 2})
false

Notes

If enumerable?/1 returns false for either store then this function will raise a Mnemonix.Features.Enumerable.Error.

Depending on the underlying store types this function may be very inefficient.

Link to this function keys(store) View Source
keys(Mnemonix.store()) :: [Mnemonix.key()] | no_return()

Returns all keys in store.

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Examples

iex> Mnemonix.keys Mnemonix.new(%{a: 1, b: 2})
[:a, :b]

iex> Mnemonix.keys Mnemonix.new
[]

Notes

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Depending on the underlying store this function may be very inefficient.

Link to this function to_list(store) View Source
to_list(Mnemonix.store()) ::
  [{Mnemonix.key(), Mnemonix.value()}] |
  no_return()

Returns all key/value pairs in store as a list of two-tuples.

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Examples

iex> Mnemonix.to_list Mnemonix.new(%{a: 1, b: 2})
[a: 1, b: 2]

iex> Mnemonix.to_list Mnemonix.new(%{"foo" => "bar"})
[{"foo", "bar"}]

iex> Mnemonix.to_list Mnemonix.new
[]

iex> {:ok, store} = Mnemonix.start_link(Mnemonix.Stores.Memcachex)
iex> Mnemonix.to_list store
** (Mnemonix.Features.Enumerable.Error) Mnemonix.Stores.Memcachex cannot be exhaustively iterated over

Notes

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Depending on the underlying store this function may be very inefficient.

Link to this function values(store) View Source
values(Mnemonix.store()) :: [Mnemonix.value()] | no_return()

Returns all values in store.

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Examples

iex> Mnemonix.values Mnemonix.new(%{a: 1, b: 2})
[1, 2]
iex> Mnemonix.values Mnemonix.new
[]

Notes

If enumerable?/1 returns false then this function will raise a Mnemonix.Features.Enumerable.Error.

Depending on the underlying store this function may be very inefficient.