aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/ext
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 12:47:11 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 12:47:11 +0100
commit5aa24ac572ab5451e187f9accfa6833634c58215 (patch)
tree45b9daab20e182dcc5f65ec0271727fb847f6e7d /aoc-2020-gleam/src/ext
parent1b8b85dd5f0aead5fb97ee9d8aa99d877c6a79e7 (diff)
downloadgleam_aoc2020-5aa24ac572ab5451e187f9accfa6833634c58215.tar.gz
gleam_aoc2020-5aa24ac572ab5451e187f9accfa6833634c58215.zip
Solve part 1 of day 24
Diffstat (limited to 'aoc-2020-gleam/src/ext')
-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)
+ }
+}