aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/ext/setx.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'aoc-2020-gleam/src/ext/setx.gleam')
-rw-r--r--aoc-2020-gleam/src/ext/setx.gleam16
1 files changed, 12 insertions, 4 deletions
diff --git a/aoc-2020-gleam/src/ext/setx.gleam b/aoc-2020-gleam/src/ext/setx.gleam
index 68d185a..6df9256 100644
--- a/aoc-2020-gleam/src/ext/setx.gleam
+++ b/aoc-2020-gleam/src/ext/setx.gleam
@@ -3,16 +3,24 @@ import gleam/set.{type Set}
import gleam/iterator as iter
import ext/iteratorx as iterx
-pub fn count(set: Set(a), satisfying predicate: fn(a) -> Bool) -> Int {
- set
+pub fn count(s: Set(a), satisfying predicate: fn(a) -> Bool) -> Int {
+ s
|> set.to_list
|> iter.from_list
|> iterx.count(satisfying: predicate)
}
-pub fn map(set: Set(a), with fun: fn(a) -> b) -> Set(b) {
- set
+pub fn map(s: Set(a), with fun: fn(a) -> b) -> Set(b) {
+ s
|> set.to_list
|> list.map(with: fun)
|> set.from_list
}
+
+pub fn toggle(in s: Set(a), this value: a) -> Set(a) {
+ s
+ |> case set.contains(in: s, this: value) {
+ True -> set.delete(from: _, this: value)
+ False -> set.insert(into: _, this: value)
+ }
+}