RaftEx.Domain.Utils
(raft_ex v0.3.1)
View Source
General-purpose utilities used across the RaftEx codebase.
Covers type coercions, UID generation, file helpers, parallel execution, and string/path utilities.
Summary
Functions
Prepend item to list.
Derive a safe string from s by keeping only URL-safe base64 characters,
truncated to num characters.
Shuffle a list using Fisher-Yates (via random sort keys).
Generate a random UID with no prefix.
Generate a UID with an optional binary prefix.
Apply fun to each element of elements in parallel, collecting results
into {:ok, successes, failures}.
Extract the node from a server id, defaulting to node() for bare atoms.
Extract the local registered name from a {name, node} server id.
Return true iff str contains only URL-safe base64 characters.
Zero-pad num to a 16-character uppercase hex string.
Functions
Prepend item to list.
@spec derive_safe_string(binary(), pos_integer()) :: binary()
Derive a safe string from s by keeping only URL-safe base64 characters,
truncated to num characters.
Shuffle a list using Fisher-Yates (via random sort keys).
@spec make_uid() :: binary()
Generate a random UID with no prefix.
Generate a UID with an optional binary prefix.
The prefix is prepended as-is; a random 12-character
alphanumeric suffix is appended.
@spec partition_parallel((term() -> boolean()), list(), timeout()) :: {:ok, list(), list()} | {:error, term()}
Apply fun to each element of elements in parallel, collecting results
into {:ok, successes, failures}.
fun must return true (success) or false (failure).
Fails with {:error, {:partition_parallel_timeout, ...}} if timeout ms elapses.
@spec ra_server_id_node(RaftEx.Domain.Types.server_id() | atom()) :: node()
Extract the node from a server id, defaulting to node() for bare atoms.
@spec ra_server_id_to_local_name(RaftEx.Domain.Types.server_id() | atom()) :: atom()
Extract the local registered name from a {name, node} server id.
Return true iff str contains only URL-safe base64 characters.
@spec zpad_extract_num(binary()) :: non_neg_integer()
@spec zpad_filename(binary(), binary(), non_neg_integer()) :: binary()
@spec zpad_hex(non_neg_integer()) :: binary()
Zero-pad num to a 16-character uppercase hex string.