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.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) {