From 51a1fcbd0e42b25238877d3ad05d1690e8bc1553 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Wed, 3 Jan 2024 19:48:25 +0000 Subject: More stdlib --- .../lesson03_dict_module/code.gleam | 14 ++++++++ .../lesson03_dict_module/text.html | 40 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/content/chapter4_standard_library/lesson03_dict_module/code.gleam create mode 100644 src/content/chapter4_standard_library/lesson03_dict_module/text.html (limited to 'src/content/chapter4_standard_library/lesson03_dict_module') 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 @@ +

+ The + gleam/dict + standard library module defines Gleam's Dict 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. +

+ +

+ new + and + new + can be used to create new dicts. +

+ +

+ insert + and + delete + are used to add and remove items from a dict. +

+

+ Like lists, dicts are immutable. Inserting or deleting an item from a dict + will return a new dict with the item added or removed. +

+

+ 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. +

-- cgit v1.2.3