aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter4_standard_library/lesson03_dict_module
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-01-03 19:48:25 +0000
committerLouis Pilfold <louis@lpil.uk>2024-01-03 19:48:25 +0000
commit51a1fcbd0e42b25238877d3ad05d1690e8bc1553 (patch)
tree36e8f8ad1ace4874a9c7515a8d381c5616f52d46 /src/content/chapter4_standard_library/lesson03_dict_module
parentf3eaea54080300a85e7acb63a38b0bf5f7c6b531 (diff)
downloadtour-51a1fcbd0e42b25238877d3ad05d1690e8bc1553.tar.gz
tour-51a1fcbd0e42b25238877d3ad05d1690e8bc1553.zip
More stdlib
Diffstat (limited to 'src/content/chapter4_standard_library/lesson03_dict_module')
-rw-r--r--src/content/chapter4_standard_library/lesson03_dict_module/code.gleam14
-rw-r--r--src/content/chapter4_standard_library/lesson03_dict_module/text.html40
2 files changed, 54 insertions, 0 deletions
diff --git a/src/content/chapter4_standard_library/lesson03_dict_module/code.gleam b/src/content/chapter4_standard_library/lesson03_dict_module/code.gleam
new file mode 100644
index 0000000..02c72c0
--- /dev/null
+++ b/src/content/chapter4_standard_library/lesson03_dict_module/code.gleam
@@ -0,0 +1,14 @@
+import gleam/io
+import gleam/dict
+
+pub fn main() {
+ let scores = dict.from_list([#("Lucy", 13), #("Drew", 15)])
+ io.debug(scores)
+
+ let scores =
+ scores
+ |> dict.insert("Bushra", 16)
+ |> dict.insert("Darius", 14)
+ |> dict.delete("Drew")
+ io.debug(scores)
+}
diff --git a/src/content/chapter4_standard_library/lesson03_dict_module/text.html b/src/content/chapter4_standard_library/lesson03_dict_module/text.html
new file mode 100644
index 0000000..5e60ba2
--- /dev/null
+++ b/src/content/chapter4_standard_library/lesson03_dict_module/text.html
@@ -0,0 +1,40 @@
+<p>
+ The
+ <a href="https://hexdocs.pm/gleam_stdlib/gleam/dict.html"
+ ><code>gleam/dict</code></a
+ >
+ standard library module defines Gleam's <code>Dict</code> type and functions
+ for working with it. A dict is a collection of keys and values which other
+ languages may call a hashmap or table.
+</p>
+
+<p>
+ <a href="https://hexdocs.pm/gleam_stdlib/gleam/dict.html#new"
+ ><code>new</code></a
+ >
+ and
+ <a href="https://hexdocs.pm/gleam_stdlib/gleam/dict.html#from_list"
+ ><code>new</code></a
+ >
+ can be used to create new dicts.
+</p>
+
+<p>
+ <a href="https://hexdocs.pm/gleam_stdlib/gleam/dict.html#insert"
+ ><code>insert</code></a
+ >
+ and
+ <a href="https://hexdocs.pm/gleam_stdlib/gleam/dict.html#delete"
+ ><code>delete</code></a
+ >
+ are used to add and remove items from a dict.
+</p>
+<p>
+ Like lists, dicts are immutable. Inserting or deleting an item from a dict
+ will return a new dict with the item added or removed.
+</p>
+<p>
+ Dicts are unordered! If it appears that the items in a dict are in a certain
+ order this is incidental and should not be relied upon. Any ordering may
+ change without warning in future versions or on different runtimes.
+</p>