Macaw.Layers.Names (macaw_layers v0.2.2)

Copy Markdown View Source

Names a document declares (spec/01 §1): a source, a field, a variable, a frame, a style, a fragment's key.

A name is a string. Elixir input may spell one as an atom, which is read as the string of the same spelling with Atom.to_string/1, which makes no atom; and a category value is matched by spelling, so :ok and "ok" are one value. Nothing here makes an atom from a document's data.

Ported from visualize's Visualize.Chart.Names.

Summary

Functions

A category value as it is compared: an atom other than nil, true and false by its spelling, anything else as it is.

Map.fetch/2 by spelling, through key/2.

A name in a guard: a string, or an atom other than nil, true and false.

The key of map that spells name: the name itself, or the key of the other spelling.

A plain map's keys as names, values untouched; a struct or a non-map as it is.

A name as a document holds it: an atom's spelling, a string as it is, and anything else (a library id {kind, n}, a malformed value a validator names) untouched.

Whether a value is a name: a non-empty string, or an atom name/1 reads as one.

Whether two category values are one: equal, or the same spelling.

Functions

category(value)

@spec category(term()) :: term()

A category value as it is compared: an atom other than nil, true and false by its spelling, anything else as it is.

fetch(map, name)

@spec fetch(map(), term()) :: {:ok, term()} | :error

Map.fetch/2 by spelling, through key/2.

is_name(v)

(macro)

A name in a guard: a string, or an atom other than nil, true and false.

key(map, name)

@spec key(map(), term()) :: {:ok, term()} | :error

The key of map that spells name: the name itself, or the key of the other spelling.

How a document's name finds a host's entry, keyed as the host keyed it (a source in a pool, a variable's value), without an atom made.

keys(map)

@spec keys(term()) :: term()

A plain map's keys as names, values untouched; a struct or a non-map as it is.

name(name)

@spec name(term()) :: term()

A name as a document holds it: an atom's spelling, a string as it is, and anything else (a library id {kind, n}, a malformed value a validator names) untouched.

iex> Macaw.Layers.Names.name(:sales)
"sales"
iex> Macaw.Layers.Names.name({:id, 1})
{:id, 1}

name?(name)

@spec name?(term()) :: boolean()

Whether a value is a name: a non-empty string, or an atom name/1 reads as one.

same?(a, a)

@spec same?(term(), term()) :: boolean()

Whether two category values are one: equal, or the same spelling.