aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuslan Ustits <ustitsruslan@gmail.com>2024-05-29 08:40:18 +0100
committerLouis Pilfold <louis@lpil.uk>2024-05-29 10:05:30 +0100
commit220b6ce60aa143446f115980a459d8745f1225a1 (patch)
tree6c8ef3689a797296683eb348293e5a35fe08b7b5 /src
parent99643d8fd40d44b828d8f3298d5282e356709f41 (diff)
downloadgleam_stdlib-220b6ce60aa143446f115980a459d8745f1225a1.tar.gz
gleam_stdlib-220b6ce60aa143446f115980a459d8745f1225a1.zip
Add is_empty to dict
Diffstat (limited to 'src')
-rw-r--r--src/gleam/dict.gleam18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gleam/dict.gleam b/src/gleam/dict.gleam
index f44daa3..99ca30c 100644
--- a/src/gleam/dict.gleam
+++ b/src/gleam/dict.gleam
@@ -35,6 +35,24 @@ pub type Dict(key, value)
@external(javascript, "../gleam_stdlib.mjs", "map_size")
pub fn size(dict: Dict(k, v)) -> Int
+/// Determines whether or not the dict is empty.
+///
+/// ## Examples
+///
+/// ```gleam
+/// new() |> is_empty
+/// // -> True
+/// ```
+///
+/// ```gleam
+/// new() |> insert("b", 1) |> is_empty
+/// // -> False
+/// ```
+///
+pub fn is_empty(dict: Dict(a, b)) -> Bool {
+ dict == new()
+}
+
/// Converts the dict to a list of 2-element tuples `#(key, value)`, one for
/// each key-value pair in the dict.
///