Skip to content
/ reather Public

Either transformed Reader monad (reather = REAder + eiTHER)

License

Notifications You must be signed in to change notification settings

jechol/reather

Repository files navigation

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

About

Either transformed Reader monad (reather = REAder + eiTHER)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages