https://github.com/jechol/reather
Either transformed Reader monad (reather = REAder + eiTHER)
https://github.com/jechol/reather
Last synced: about 1 year ago
JSON representation
Either transformed Reader monad (reather = REAder + eiTHER)
- Host: GitHub
- URL: https://github.com/jechol/reather
- Owner: jechol
- License: other
- Created: 2022-01-24T09:16:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-03T08:35:36.000Z (about 2 years ago)
- Last Synced: 2025-04-10T06:09:14.705Z (about 1 year ago)
- Language: Elixir
- Homepage:
- Size: 333 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/jechol/reather/actions)
[](https://hex.pm/packages/reather)
[](https://github.com/jechol/reather/blob/main/LICENSE.md)
[](https://coveralls.io/github/jechol/reather?branch=main)
`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`:
```elixir
def deps do
[{:reather, "~> 0.1"}]
end
```
To format `reather` like `def`, add following to your `.formatter.exs`
```elixir
locals_without_parens: [reather: 2]
```
## Usage
#### `reather`, `ask`, `let`, `run`
```elixir
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](LICENSE.md) file for details