File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
10
10
For a steady stream of TILs from a variety of rocketeers, checkout
11
11
[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
12
12
13
- _ 782 TILs and counting..._
13
+ _ 783 TILs and counting..._
14
14
15
15
---
16
16
@@ -125,6 +125,7 @@ _782 TILs and counting..._
125
125
- [ Check For A Substring Match] ( elixir/check-for-a-substring-match.md )
126
126
- [ Check List Membership] ( elixir/check-list-membership.md )
127
127
- [ Comparing DateTime Structs] ( elixir/comparing-datetime-structs.md )
128
+ - [ Compute Intermediate Values In A With Construct] ( elixir/compute-intermediate-values-in-a-with-construct.md )
128
129
- [ Compute md5 Digest Of A String] ( elixir/compute-md5-digest-of-a-string.md )
129
130
- [ Counting Records With Ecto] ( elixir/counting-records-with-ecto.md )
130
131
- [ Create A Date With The Date Sigil] ( elixir/create-a-date-with-the-date-sigil.md )
Original file line number Diff line number Diff line change
1
+ # Compute Intermediate Values In A With Construct
2
+
3
+ The expressions you use in a ` with ` construct do not have to contain the
4
+ ` <- ` syntax. You can pattern match and bind values along the way as well.
5
+
6
+ ``` elixir
7
+ with %{id: id} <- get_user ()
8
+ url = " /api/#{ id } /blogs" ,
9
+ %{status_code: 200 , body: body} <- HTTPoison .get (url),
10
+ {:ok , decoded_body} <- Poison .decode (body) do
11
+ {:ok , decoded_body}
12
+ end
13
+ ```
14
+
15
+ In the above (sorta contrived) example we were able to construct a URL in
16
+ the middle of the series of expressions.
17
+
18
+ The values we compute inline will be closed into the ` with ` construct, so
19
+ they won't leak.
20
+
21
+ See the [ ` with `
22
+ docs] ( https://hexdocs.pm/elixir/Kernel.SpecialForms.html#with/1 ) for more
23
+ details.
You can’t perform that action at this time.
0 commit comments