View Source Estructura.Lazy (estructura v1.4.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

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

Functions

Link to this function

apply(lazy, lazy_data, key \\ nil)

View Source
@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")
Link to this function

new(getter, expires_in \\ :never)

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

Create the new struct with the getter passed as an argument

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

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