Skip to content

Use ex syntax highlighting in readme #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,57 @@ Instead of `|>` we can use `>>>` to pipe `{:ok, val} | {:error, error}` returnin

As written in `test/rop_test.exs`:

use Rop
```ex
use Rop
```

Using Rop defines `>>>` operator.

test "Count to 3" do
assert (ok(0) >>> ok >>> ok) == {:ok, 3}
end
```ex
test "Count to 3" do
assert (ok(0) >>> ok >>> ok) == {:ok, 3}
end
```

We increase `0` three times to end up with `{:ok, 3}`.

test "Error" do
assert (ok(0) >>> error) == {:error, "Error at 1"}
end
```ex
test "Error" do
assert (ok(0) >>> error) == {:error, "Error at 1"}
end
```

Error function always return error.

test "Error propagation" do
assert (ok(0) >>> error >>> ok) == {:error, "Error at 1"}
end
```ex
test "Error propagation" do
assert (ok(0) >>> error >>> ok) == {:error, "Error at 1"}
end
```

Error was propagated and second `ok` was not called.

test "First error is returned" do
assert (ok(0) >>> error >>> error) == {:error, "Error at 1"}
end
```ex
test "First error is returned" do
assert (ok(0) >>> error >>> error) == {:error, "Error at 1"}
end
```

Only first error is returned, since next `error` is never called.

defp ok(cnt) do
{:ok, cnt + 1}
end
```ex
defp ok(cnt) do
{:ok, cnt + 1}
end

```
`ok/1` function takes value and increases it, returning standard `{:ok, val}` response.

defp error(cnt) do
{:error, "Error at #{cnt}"}
end
```ex
defp error(cnt) do
{:error, "Error at #{cnt}"}
end
```

`error/1` function takes value and returns standard `{:error, string}` that identifies where error was called.

Expand Down