Skip to content
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

Swap out "gender" for "pronouns" #119

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
54 changes: 27 additions & 27 deletions _includes/ch/10.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 id='chapter-10'>10. Working with maps</h2>
Similar to this, we could <em>enumerate</em> through a map. If we were to take one of our maps from earlier...
</p>

<pre><code>%{name: "Izzy", age: "30ish", gender: "Female"}</code></pre>
<pre><code>%{name: "Izzy", age: "30ish", pronouns: "she/her"}</code></pre>

<p>
...and write each key and value pair down, they may look something like this:
Expand All @@ -31,17 +31,17 @@ <h2 id='chapter-10'>10. Working with maps</h2>
<dd>Izzy</dd>
<dt><strong>Age</strong></dt>
<dd>30ish</dd>
<dt><strong>Gender</strong></dt>
<dd>Female</dd>
<dt><strong>pronouns</strong></dt>
<dd>she/her</dd>
</dl>
</blockquote>

<p>
But we never got around to actually showing you how this was done! Well, enough dilly-dallying, here's an example:
</p>

<pre><code>iex> person = %{name: "Izzy", age: "30ish", gender: "Female"}
%{age: "30ish", gender: "Female", name: "Izzy"}
<pre><code>iex> person = %{name: "Izzy", age: "30ish", pronouns: "she/her"}
%{age: "30ish", pronouns: "she/her", name: "Izzy"}
iex> Enum.each(person, fn ({key, value}) -> IO.puts value end)
</code></pre>

Expand Down Expand Up @@ -85,7 +85,7 @@ <h2 id='chapter-10'>10. Working with maps</h2>

<pre><code>iex> Enum.each(person, fn ({key, value}) -> IO.puts value end)
30ish
Female
she/her
Izzy
:ok</code></pre>

Expand Down Expand Up @@ -134,7 +134,7 @@ <h3>Mapping over maps</h3>
</p>

<pre>
<code>iex> person = %{name: "Izzy", age: "30ish", gender: "Female"}</code></pre>
<code>iex> person = %{name: "Izzy", age: "30ish", pronouns: "she/her"}</code></pre>

<p>
We should try to use another map for this section. Hmmmm. How about a map with the days of the week and their
Expand Down Expand Up @@ -518,8 +518,8 @@ <h4>Finding a key's value</h4>
key by using square brackets.
</p>

<pre><code>iex> person = %{"gender" => "Female", "age" => "30ish", "name" => "Izzy"}
%{"age" => "30ish", "gender" => "Female", "name" => "Izzy"}
<pre><code>iex> person = %{"pronouns" => "she/her", "age" => "30ish", "name" => "Izzy"}
%{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"}
iex> person["name"]
"Izzy"</code></pre>

Expand Down Expand Up @@ -609,10 +609,10 @@ <h4>Finding a key's value</h4>
</p>

<pre><code>iex> those_who_are_assembled = [
%{age: "30ish", gender: "Female", name: "Izzy"}
%{age: "30ish", pronouns: "she/her", name: "Izzy"}
]
iex> [first_person = %{name: first_name} | others] = those_who_are_assembled
[%{age: "30ish", gender: "Female", name: "Izzy"}]
[%{age: "30ish", pronouns: "she/her", name: "Izzy"}]
iex> first_name
"Izzy"</code></pre>

Expand Down Expand Up @@ -669,7 +669,7 @@ <h4>put</h4>
data that we have on Izzy so far:
</p>

<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "gender" => "Female"}</code></pre>
<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "pronouns" => "she/her"}</code></pre>

<p>
Recently, we've found out that Izzy is from Australia. That would explain
Expand All @@ -683,7 +683,7 @@ <h4>put</h4>
<pre><code>iex> izzy = %{
<span class='unfocussed'>"name" => "Izzy"</span>,
"age" => "40ish",
<span class='unfocussed'>"gender" => "Female",</span>
<span class='unfocussed'>"pronouns" => "she/her",</span>
"country" => "Australia",
}</code></pre>

Expand All @@ -694,7 +694,7 @@ <h4>put</h4>
</p>

<pre><code>iex> izzy = Map.put(izzy, "age", "40ish")
%{"age" => "40ish", "gender" => "Female", "name" => "Izzy"}</code></pre>
%{"age" => "40ish", "pronouns" => "she/her", "name" => "Izzy"}</code></pre>

<p>
Ah that's so much better than writing the whole map from scratch! We can
Expand All @@ -710,7 +710,7 @@ <h4>put</h4>
</p>

<pre><code>izzy |> Map.put("age", "40ish") |> Map.put("country", "Australia")
%{"age" => "40ish", "country" => "Australia", "gender" => "Female", "name" => "Izzy"}</code></pre>
%{"age" => "40ish", "country" => "Australia", "pronouns" => "she/her", "name" => "Izzy"}</code></pre>

<p>
This time, we've updated the value under the <code>age</code> key, <em>and</em> we've also added a new key here
Expand All @@ -719,7 +719,7 @@ <h4>put</h4>
</p>

<pre><code>izzy
%{"age" => "30ish", "gender" => "Female", "name" => "Izzy"}</code></pre>
%{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"}</code></pre>

<p>
This is because of that <em>immutability</em> thing we talked about a few chapters ago. Data in Elixir never changes
Expand All @@ -729,7 +729,7 @@ <h4>put</h4>
</p>

<pre><code>izzy = izzy |> Map.put("age", "40ish") |> Map.put("country", "Australia")
%{"age" => "40ish", "country" => "Australia", "gender" => "Female", "name" => "Izzy"}</code></pre>
%{"age" => "40ish", "country" => "Australia", "pronouns" => "she/her", "name" => "Izzy"}</code></pre>

<p>
From that point onwards, our code would know that Izzy is 40ish and from Australia. Phew.
Expand All @@ -747,7 +747,7 @@ <h4>merge</h4>
Let's change the data that we have on Izzy back to what it was at the start of this chapter:
</p>

<pre><code>izzy = %{"name" => "Izzy", "age" => "30ish", "gender" => "Female"}</code></pre>
<pre><code>izzy = %{"name" => "Izzy", "age" => "30ish", "pronouns" => "she/her"}</code></pre>

<p>
This'll make it easier to show what <code>Map.merge/2</code> does.
Expand All @@ -760,7 +760,7 @@ <h4>merge</h4>
%{
"age" => "40ish",
"country" => "Australia",
"gender" => "Female",
"pronouns" => "she/her",
"name" => "Izzy"
}</code></pre>

Expand Down Expand Up @@ -788,10 +788,10 @@ <h4>Pipe Merging</h4>
way, which we'll call <em>pipe merging</em>. The syntax goes like this:
</p>

<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "gender" => "Female"}
%{"age" => "30ish", "gender" => "Female", "name" => "Izzy"}
<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "pronouns" => "she/her"}
%{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"}
iex> %{izzy | "age" => "40ish", "name" => "Isadora"}
%{"age" => "40ish", "gender" => "Female", "name" => "Isadora"}</code></pre>
%{"age" => "40ish", "pronouns" => "she/her", "name" => "Isadora"}</code></pre>

<p>
This syntax <em>looks</em> like a map, but it's split in two. On the left hand side, inside the map syntax, we have
Expand All @@ -805,12 +805,12 @@ <h4>Pipe Merging</h4>
syntax:
</p>

<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "gender" => "Female"}
%{"age" => "30ish", "gender" => "Female", "name" => "Izzy"}
<pre><code>iex> izzy = %{"name" => "Izzy", "age" => "30ish", "pronouns" => "she/her"}
%{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"}
iex> %{izzy | "country" => "Australia"}
<span class='console-red'>
** (KeyError) key "country" not found in: %{"age" => "30ish", "gender" => "Female", "name" => "Izzy"}
(stdlib) :maps.update("country", "Australia", %{"age" => "30ish", "gender" => "Female", "name" => "Izzy"})</span></code></pre>
** (KeyError) key "country" not found in: %{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"}
(stdlib) :maps.update("country", "Australia", %{"age" => "30ish", "pronouns" => "she/her", "name" => "Izzy"})</span></code></pre>


<p>
Expand All @@ -829,7 +829,7 @@ <h4>delete</h4>
</p>

<pre><code>izzy = Map.delete(izzy, "country")
%{"age" => "40ish", "gender" => "Female", "name" => "Izzy"}
%{"age" => "40ish", "pronouns" => "she/her", "name" => "Izzy"}
</code></pre>

<p>
Expand Down
38 changes: 19 additions & 19 deletions _includes/ch/13.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,56 +84,56 @@ <h4>The arrow and v helpers</h4>
Let's say that we've been working in <code>iex</code> and we've written this code:
</p>

<pre><code>iex(1)> %{name: "Izzy", age: "30ish", gender: "Female"}
iex(2)> %{name: "Ryan", age: "30ish", gender: "Male"}</code></pre>
<pre><code>iex(1)> %{name: "Izzy", age: "30ish", pronouns: "she/her"}
iex(2)> %{name: "Ryan", age: "30ish", pronouns: "he/him"}</code></pre>

<p>
Oh drat. We've just realised that wanted to assign these to variables, but forgot to. One way we can get that
value again is by pressing the up-arrow on our keyboard. We'll then see this:
</p>

<pre><code>iex(1)> %{name: "Izzy", age: "30ish", gender: "Female"}
%{age: "30ish", gender: "Female", name: "Izzy"}
iex(2)> %{name: "Ryan", age: "30ish", gender: "Male"}
%{name: "Ryan", age: "30ish", gender: "Male"}
iex(3)> %{name: "Ryan", age: "30ish", gender: "Male"}</code></pre>
<pre><code>iex(1)> %{name: "Izzy", age: "30ish", pronouns: "she/her"}
%{age: "30ish", pronouns: "she/her", name: "Izzy"}
iex(2)> %{name: "Ryan", age: "30ish", pronouns: "he/him"}
%{name: "Ryan", age: "30ish", pronouns: "he/him"}
iex(3)> %{name: "Ryan", age: "30ish", pronouns: "he/him"}</code></pre>

<p>
Our terminal helpfully brings back the last value when we push the up-arrow. But if we push the up-arrow again,
look what happens:
</p>

<pre><code>iex(1)> %{name: "Izzy", age: "30ish", gender: "Female"}
%{age: "30ish", gender: "Female", name: "Izzy"}
iex(2)> %{name: "Ryan", age: "30ish", gender: "Male"}
%{name: "Ryan", age: "30ish", gender: "Male"}
iex(3)> %{age: "30ish", gender: "Female", name: "Izzy"}</code></pre>
<pre><code>iex(1)> %{name: "Izzy", age: "30ish", pronouns: "she/her"}
%{age: "30ish", pronouns: "she/her", name: "Izzy"}
iex(2)> %{name: "Ryan", age: "30ish", pronouns: "he/him"}
%{name: "Ryan", age: "30ish", pronouns: "he/him"}
iex(3)> %{age: "30ish", pronouns: "she/her", name: "Izzy"}</code></pre>

<p>
We're now back to the first value again! We could then go to the start of this line (by pushing the left-arrow, or
<kbd>Ctrl+A</kbd>) and assign it to a variable if we wished:
</p>

<pre><code>iex(3)> izzy = %{age: "30ish", gender: "Female", name: "Izzy"}
%{age: "30ish", gender: "Female", name: "Izzy"}</code></pre>
<pre><code>iex(3)> izzy = %{age: "30ish", pronouns: "she/her", name: "Izzy"}
%{age: "30ish", pronouns: "she/her", name: "Izzy"}</code></pre>

<p>
If we push the up-arrow again here, we'll get the same as line 3; the line we just had:
</p>

<pre><code>iex(4)> izzy = %{age: "30ish", gender: "Female", name: "Izzy"}</code></pre>
<pre><code>iex(4)> izzy = %{age: "30ish", pronouns: "she/her", name: "Izzy"}</code></pre>

<p>
If we push it a second time, we'll get the same as line 2.
</p>

<pre><code>iex(4)> %{name: "Ryan", age: "30ish", gender: "Male"}</code></pre>
<pre><code>iex(4)> %{name: "Ryan", age: "30ish", pronouns: "he/him"}</code></pre>

<p>
If we push the down-arrow, we'll go back to line 3.
</p>

<pre><code>iex(4)> izzy = %{age: "30ish", gender: "Female", name: "Izzy"}</code></pre>
<pre><code>iex(4)> izzy = %{age: "30ish", pronouns: "she/her", name: "Izzy"}</code></pre>

<p>
This is how we can navigate up and down, or back and forward (depending your viewpoint) through the history of
Expand All @@ -147,7 +147,7 @@ <h4>The arrow and v helpers</h4>
</p>

<pre><code>iex(4)> ryan = v(2)
%{name: "Ryan", age: "30ish", gender: "Male"}</code></pre>
%{name: "Ryan", age: "30ish", pronouns: "he/him"}</code></pre>

<p>
This code can be read as: find the 2nd value from the prompt, and assign it to a variable called
Expand All @@ -156,7 +156,7 @@ <h4>The arrow and v helpers</h4>
</p>

<pre><code>iex(5)> ryan = v 2
%{name: "Ryan", age: "30ish", gender: "Male"}</code></pre>
%{name: "Ryan", age: "30ish", pronouns: "he/him"}</code></pre>
</section>

<section>
Expand Down
16 changes: 8 additions & 8 deletions _includes/ch/3.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,31 @@ <h2 id='chapter-3'>3. Lovely lists</h2>
And so Izzy continues. She disappears into the crowd directly to our right, and somehow re-appears within mere
seconds on our left. This is despite the density of the crowd. Amazing stuff. She then asks: "Hey Mr. Author Guy, I
want to also track people's ages so that I can do some statistics on who exactly is assembled here. Oh, and I want
to track their gender too. But a list doesn't seem very suitable for this. How can I do this?"
to track their pronouns too. But a list doesn't seem very suitable for this. How can I do this?"
</p>

<p>
Well Izzy, there's more than one way you could do this. If all you wanted to track about a person was their name,
their age and their gender, you could make each item in the list its own list:
their age and their pronouns, you could make each item in the list its own list:
</p>

<pre>
<code>iex> those_who_are_assembled = [
...> ["Izzy", "30ish", "Female"],
...> ["The Author", "30ish", "Male"],
...> ["Izzy", "30ish", "she/her"],
...> ["The Author", "30ish", "he/him"],
...> ]</code></pre>

<p>
These lists-inside-of-lists would be called <em>sub-lists</em>. You would then have to keep in mind that the first
item in each sub-list is the name, the second is the age and the third is the gender. What if you (or someone else,
using your computer) forgot the order and started adding in people, with age and gender swapping positions?
item in each sub-list is the name, the second is the age and the third is the pronouns. What if you (or someone else,
using your computer) forgot the order and started adding in people, with age and pronouns swapping positions?
</p>

<pre>
<code>iex> those_who_are_assembled = [
...> ["Izzy", "30ish", "Female"],
...> ["Izzy", "30ish", "she/her"],
... a long time passes ...
...> ["Izzy the Younger", "Female", "20ish"],
...> ["Izzy the Younger", "she/her", "20ish"],
...> ]</code></pre>

<p>
Expand Down
Loading