reather
[ˈriːθə(r)] is def
for Witchcraft's Reader + Either monads.
The package can be installed by adding reather
to your list of dependencies
in mix.exs
:
def deps do
[{:reather, "~> 0.1"}]
end
To format reather
like def
, add following to your .formatter.exs
locals_without_parens: [reather: 2]
defmodule Example do
use Reather
reather next(number) do
n <- number
%{step: step} <- Reather.ask()
let sum = n + step
sum
end
test "next/1" do
assert Right.new(15) == next(10) |> Reather.run(%{step: 5})
assert Right.new(15) == next(Right.new(10)) |> Reather.run(%{step: 5})
assert Right.new(15) == next(Reather.of(10)) |> Reather.run(%{step: 5})
assert Left.new(:NaN) == next(Left.new(:NaN)) |> Reather.run(%{step: 5})
assert Left.new(:NaN) == next(Reather.of(Left.new(:NaN))) |> Reather.run(%{step: 5})
end
end
This project is licensed under the MIT License - see the LICENSE file for details