# `Estructura.Lazy`
[🔗](https://github.com/am-kantox/estructura/blob/v1.13.0/lib/estructura/lazy.ex#L1)

The field stub allowing lazy instantiation of `Estructura` fields.

# `cached`

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

# `getter`

```elixir
@type getter() :: (value() -&gt; cached()) | (key(), value() -&gt; cached())
```

# `key`

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

# `t`

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

# `value`

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

# `apply`

```elixir
@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`

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

Create the new struct with the getter passed as an argument

# `stale?`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
