From e5fcc03e3e0f718a33f36da80415cadfcfbcb71b Mon Sep 17 00:00:00 2001 From: kyleVsteger Date: Sun, 12 Dec 2021 18:25:41 -0500 Subject: [PATCH] Elixir: Add `with` Example (#1731) --- elixir.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/elixir.md b/elixir.md index 3928228bf..a6754d648 100644 --- a/elixir.md +++ b/elixir.md @@ -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