Yarnspinnex.Vars (yarnspinnex v0.3.0)

Copy Markdown View Source

Name lookup shared by the interpreter and Yarnspinnex.Ops: $player finds "player" or :player in a map or Yarnspinnex.Projection, string key first. A keyword list is accepted at the top level only, as context (lookup!/1) or vars (normalize/1); nested values are maps.

Summary

Types

What a host may pass as context: read by name, never copied or rewritten.

What fetch/2 reads: a context or field value after lookup!/1.

What a host may pass as variables: normalized once into the cursor.

Functions

Looks name up as a string key, then as an existing atom; :error when neither is there.

The host's context as fetch/2 reads it: a map or Yarnspinnex.Projection as is, a keyword list as a map. Raises on anything else, a domain struct included.

Builds the string-keyed variable map a cursor carries from a map or keyword list.

Types

collection()

@type collection() ::
  %{optional(atom() | String.t()) => term()}
  | keyword()
  | Yarnspinnex.Projection.t()

What a host may pass as context: read by name, never copied or rewritten.

lookup()

@type lookup() ::
  %{optional(atom() | String.t()) => term()} | Yarnspinnex.Projection.t()

What fetch/2 reads: a context or field value after lookup!/1.

vars()

@type vars() :: %{optional(atom() | String.t()) => term()} | keyword()

What a host may pass as variables: normalized once into the cursor.

Functions

fetch(map, name)

@spec fetch(lookup(), String.t()) :: {:ok, term()} | :error

Looks name up as a string key, then as an existing atom; :error when neither is there.

lookup!(projection)

@spec lookup!(term()) :: lookup()

The host's context as fetch/2 reads it: a map or Yarnspinnex.Projection as is, a keyword list as a map. Raises on anything else, a domain struct included.

normalize(vars)

@spec normalize(vars()) :: %{optional(String.t()) => term()}

Builds the string-keyed variable map a cursor carries from a map or keyword list.