Elixir: Add `with` Example (#1731)
This commit is contained in:
parent
21c62b3729
commit
e5fcc03e3e
14
elixir.md
14
elixir.md
|
@ -142,6 +142,20 @@ cond do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### With
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
with {:ok, {int, _asdf}} <- Integer.parse("123asdf"),
|
||||||
|
{:ok, datetime, _utc_offset} <- DateTime.from_iso8601("2021-10-27T12:00:00Z") do
|
||||||
|
DateTime.add(datetime, int, :second)
|
||||||
|
# optional else clause. if not provided and an error occurs, the error is returned
|
||||||
|
else
|
||||||
|
:error -> "couldn't parse integer string"
|
||||||
|
{:error, :invalid_format} -> "couldn't parse date string"
|
||||||
|
_ -> "this will never get hit because all errors are handled"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Errors
|
### Errors
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
|
|
Loading…
Reference in New Issue