View Source shards_lib (shards v1.1.1)

Common Shards Utilities.

Summary

Functions

Searches the childern of the supervisor SupPid for a child whose Nth element compares equal to Id.
Returns the value to the given Key or Default if it doesn't exist.
Searches the list of tuples KVList1 for a tuple whose Nth element compares equal to Key. Returns {Value, KVList2} if such a tuple is found, otherwise {Default, KVList1}. KVList2 is a copy of KVList1 where the first occurrence of Tuple has been removed.
Updates the given Keys by the result of calling Fun(OldValue). If Key doesn't exist, then Init is set.
Returns the key for the given object or list of objects.
Reads the file info related to a tabfile saved previously.
Converts the input data to a string.
Writes to a file a content related to a table.

Types

-type kv_list() :: [{term(), term()}].

Functions

Link to this function

get_sup_child(SupPid, Id)

View Source
-spec get_sup_child(SupPid, Id) -> Child
                       when SupPid :: pid(), Id :: term(), Child :: pid() | undefined | restarting.
Searches the childern of the supervisor SupPid for a child whose Nth element compares equal to Id.

Equivalent to keyfind(Key, KVList, undefined).

Link to this function

keyfind(Key, KVList, Default)

View Source
-spec keyfind(term(), kv_list(), term()) -> term().
Returns the value to the given Key or Default if it doesn't exist.

Equivalent to keypop(Key, KVList1, undefined).

Link to this function

keypop(Key, KVList1, Default)

View Source
-spec keypop(Key, KVList1, Default) -> {Value, KVList2}
                when
                    Key :: term(),
                    KVList1 :: kv_list(),
                    Default :: term(),
                    Value :: term(),
                    KVList2 :: kv_list().
Searches the list of tuples KVList1 for a tuple whose Nth element compares equal to Key. Returns {Value, KVList2} if such a tuple is found, otherwise {Default, KVList1}. KVList2 is a copy of KVList1 where the first occurrence of Tuple has been removed.
Link to this function

keyupdate(Fun, Keys, TupleList)

View Source

Equivalent to keyupdate(Fun, Keys, undefined, TupleList).

Link to this function

keyupdate(Fun, Keys, Init, KVList1)

View Source
-spec keyupdate(Fun, Keys, Init, KVList1) -> KVList2
                   when
                       Fun :: fun((Key :: term(), Value :: term()) -> term()),
                       Keys :: [term()],
                       Init :: term(),
                       KVList1 :: kv_list(),
                       KVList2 :: kv_list().
Updates the given Keys by the result of calling Fun(OldValue). If Key doesn't exist, then Init is set.
Link to this function

object_key(ObjOrObjs, Meta)

View Source
-spec object_key(ObjOrObjs, Meta) -> term()
                    when ObjOrObjs :: tuple() | [tuple()], Meta :: shards_meta:t().
Returns the key for the given object or list of objects.
-spec read_tabfile(shards:filename()) -> term() | no_return().
Reads the file info related to a tabfile saved previously.
-spec to_string(Data :: term()) -> string() | no_return().
Converts the input data to a string.
Link to this function

write_tabfile(Filename, Content)

View Source
-spec write_tabfile(shards:filename(), term()) -> ok | {error, term()}.
Writes to a file a content related to a table.