View Source Estructura.Lazy (estructura v1.6.1)

The field stub allowing lazy instantiation of Estructura fields.

Summary

Functions

Apply the lazy getter to the data passed as an argument

Create the new struct with the getter passed as an argument

Validates if the value is not stale yet according to expires_in setting

Types

cached()

@type cached() :: {:ok, value()} | {:error, any()}

getter()

@type getter() :: (value() -> cached()) | (key(), value() -> cached())

key()

@type key() :: Map.key()

t()

@type t() :: %Estructura.Lazy{
  expires_in: non_neg_integer() | :instantly | :never,
  timestamp: nil | DateTime.t(),
  payload: any(),
  value: cached(),
  getter: getter()
}

value()

@type value() :: Map.value()

Functions

apply(lazy, lazy_data, key \\ nil)

@spec apply(t(), %{__lazy_data__: term()} | term(), key()) :: t()

Apply the lazy getter to the data passed as an argument

Examples

iex> lazy = Estructura.Lazy.new(&System.fetch_env/1)
...> Estructura.Lazy.apply(lazy, "LANG").value
System.fetch_env("LANG")

new(getter, expires_in \\ :never)

@spec new(getter(), non_neg_integer() | :instantly | :never) :: t()

Create the new struct with the getter passed as an argument

stale?(lazy)

@spec stale?(t()) :: boolean()

Validates if the value is not stale yet according to expires_in setting