Triple.Util (triple v1.0.0)

Copy Markdown View Source

Small stateless helpers shared across the Triple client.

Summary

Functions

Drops keys whose value is nil from a map. Used when building JSON request bodies so optional/unset fields are omitted entirely rather than sent as explicit nulls.

Generates a random UUID v4 string. Handy for populating transaction_id when you don't already have a natural unique identifier on hand — Triple requires it to be unique per caller, but doesn't care what it looks like.

Functions

compact(map)

@spec compact(map()) :: map()

Drops keys whose value is nil from a map. Used when building JSON request bodies so optional/unset fields are omitted entirely rather than sent as explicit nulls.

Examples

iex> Triple.Util.compact(%{a: 1, b: nil, c: "x"})
%{a: 1, c: "x"}

generate_transaction_id()

@spec generate_transaction_id() :: String.t()

Generates a random UUID v4 string. Handy for populating transaction_id when you don't already have a natural unique identifier on hand — Triple requires it to be unique per caller, but doesn't care what it looks like.

Examples

iex> uuid = Triple.Util.generate_transaction_id()
iex> String.match?(
...>   uuid,
...>   ~r/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
...> )
true