diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/gleam/set.gleam | 12 | ||||
-rw-r--r-- | test/gleam/set_test.gleam | 8 |
3 files changed, 22 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 531cba6..9c80add 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ - Created the `iterator` module with the `unfold`, `repeatedly`, `repeat`, `from_list`, `fold`, `run`, `to_list`, `take`, `drop`, `map`, `filter`, `cycle`, and `range` functions. -- Created the `set` module with the `new`, `insert`, and `contains` functions. +- Created the `set` module with the `new`, `insert`, `delete`, and `contains` + functions. - Created the `io` module with the `print`, `println`, and `debug` functions. - Created the `queue` module with the `new`, `from_list`, `to_list`, `is_empty`, `length`, `push_back`, `push_front`, `pop_back`, `pop_front`, diff --git a/src/gleam/set.gleam b/src/gleam/set.gleam index cd7cbe0..7b52064 100644 --- a/src/gleam/set.gleam +++ b/src/gleam/set.gleam @@ -61,3 +61,15 @@ pub fn contains(in set: Set(element), this member: element) -> Bool { |> map.get(member) |> result.is_ok } + +/// Remove an element from a set. If the set does not contain the element then +/// the set is returned unchanged. +/// +/// ## Examples +/// +/// > new() |> insert(2) |> delete(2) |> contains(1) +/// False +/// +pub fn delete(from set: Set(element), this member: element) -> Set(element) { + Set(map: map.delete(set.map, member)) +} diff --git a/test/gleam/set_test.gleam b/test/gleam/set_test.gleam index 7247c5c..dcc1356 100644 --- a/test/gleam/set_test.gleam +++ b/test/gleam/set_test.gleam @@ -30,3 +30,11 @@ pub fn contains_test() { |> set.contains(this: 1) |> should.be_false } + +pub fn delete_test() { + set.new() + |> set.insert(1) + |> set.delete(1) + |> set.contains(1) + |> should.be_false +} |