Elixir: Add `with` Example (#1731)

This commit is contained in:
kyleVsteger 2021-12-12 18:25:41 -05:00 committed by GitHub
parent 21c62b3729
commit e5fcc03e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -142,6 +142,20 @@ cond do
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
```elixir