Mnemonix v0.8.0 Mnemonix.Features.Enumerable

Functions that rely on enumerating over all key/value pairs within a Mnemonix.Store.Server.

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.

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

Functions

enumerable?(store)
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.Store.Server.start_link(Mnemonix.Stores.ETS)
iex> Mnemonix.enumerable? store
true

iex> {:ok, store} = Mnemonix.Store.Server.start_link(Mnemonix.Stores.Memcachex)
iex> Mnemonix.enumerable? store
false
equal?(store1, store2)
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.

keys(store)
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.

to_list(store)
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.Store.Server.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.

values(store)
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.