Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1.56 KB

README.md

File metadata and controls

54 lines (39 loc) · 1.56 KB

mix test Hex version badge License badge Coverage Status

reather[ˈriːθə(r)] is def for Witchcraft's Reader + Either monads.

Installation

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]

Usage

reather, ask, let, run

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

License

This project is licensed under the MIT License - see the LICENSE file for details