View Source Skogsra.Type behaviour (Skogsrå v2.5.0)
This module defines the functions and behaviours for casting Skogsra types.
Summary
Callbacks
Callback for casting a value.
Functions
Uses Skogsra.Type for implementing the behaviour e.g. a naive implementation
for casting "1, 2, 3, 4" to ["1", "2", "3", "4"] would be
Casts an environment variable.
Callbacks
Callback for casting a value.
Functions
Uses Skogsra.Type for implementing the behaviour e.g. a naive implementation
for casting "1, 2, 3, 4" to ["1", "2", "3", "4"] would be:
defmodule MyList do
use Skogsra.Type
def cast(value) when is_binary(value) do
list =
value
|> String.split(~r/,/)
|> Enum.map(&String.trim/1)
{:ok, list}
end
def cast(_) do
:error
end
end
@spec cast(Skogsra.Env.t(), term()) :: {:ok, term()} | :error
Casts an environment variable.