aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/ext
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 13:33:34 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 13:33:34 +0100
commit8bafdaf384fd144a61a7d23661a6cc8d56b5d810 (patch)
treefe8eb9c334c86056bebeb3c6cba6f9069a472f09 /aoc-2020-gleam/src/ext
parent5aa24ac572ab5451e187f9accfa6833634c58215 (diff)
downloadgleam_aoc2020-8bafdaf384fd144a61a7d23661a6cc8d56b5d810.tar.gz
gleam_aoc2020-8bafdaf384fd144a61a7d23661a6cc8d56b5d810.zip
Finish day 24
Diffstat (limited to 'aoc-2020-gleam/src/ext')
-rw-r--r--aoc-2020-gleam/src/ext/setx.gleam7
1 files changed, 7 insertions, 0 deletions
diff --git a/aoc-2020-gleam/src/ext/setx.gleam b/aoc-2020-gleam/src/ext/setx.gleam
index 6df9256..4a9c0c1 100644
--- a/aoc-2020-gleam/src/ext/setx.gleam
+++ b/aoc-2020-gleam/src/ext/setx.gleam
@@ -17,6 +17,13 @@ pub fn map(s: Set(a), with fun: fn(a) -> b) -> Set(b) {
|> set.from_list
}
+pub fn flat_map(s: Set(a), with fun: fn(a) -> Set(b)) -> Set(b) {
+ s
+ |> set.to_list
+ |> list.map(with: fun)
+ |> list.fold(from: set.new(), with: set.union)
+}
+
pub fn toggle(in s: Set(a), this value: a) -> Set(a) {
s
|> case set.contains(in: s, this: value) {