Bourse.Safe (bourse v0.1.0)

Copy Markdown View Source

Safe accessors and coercions used by response normalization.

Summary

Functions

Coerces a value to a boolean when present.

Coerces a value to an integer when present.

Coerces a value to a number when present.

Coerces a value to a string when present.

Coerces a value to a lowercase string when present.

Safely reads a value from a map or list, returning default when absent.

Safely reads the first present key from a map or list.

Types

data()

@type data() :: map() | list()

key()

@type key() :: atom() | String.t() | non_neg_integer()

Functions

bool(value)

@spec bool(term()) :: boolean() | nil

Coerces a value to a boolean when present.

integer(value)

@spec integer(term()) :: integer() | nil

Coerces a value to an integer when present.

number(value)

@spec number(term()) :: number() | nil

Coerces a value to a number when present.

string(value)

@spec string(term()) :: String.t() | nil

Coerces a value to a string when present.

string_lower(value)

@spec string_lower(term()) :: String.t() | nil

Coerces a value to a lowercase string when present.

value(data, index, default)

@spec value(term(), key() | nil, term()) :: term()

Safely reads a value from a map or list, returning default when absent.

value_any(data, keys, default)

@spec value_any(term(), [key()], term()) :: term()

Safely reads the first present key from a map or list.