Fex.Lazy (fEx v0.2.0) View Source
Documentation for Fex
.
Lazy module won't execute the code. It will instead wrap it inside function and return nested function. This make the module "pure" as it's actually not executing any of its code
Example:
def allowed?(email, read_fn \ &File.read/1) do
Lazy.task(fn () -> read_fn.("list.json") end)
|> Lazy.chain(&Jason.decode/1)
|> Lazy.apply(&check_email(&1, email))
|> Lazy.fold(& &1, fn error ->
Logger.error("User service error occurred")
IO.inspect(error)
false
end)
end
Calling the above function results in a function returned. None of
the code is executed. You can "trigger" the execution by just calling
the resulted function:
iex(1)> function = allowed?("test@example.com") iex(2)> function.() true