From 8bafdaf384fd144a61a7d23661a6cc8d56b5d810 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Sat, 23 Dec 2023 13:33:34 +0100 Subject: Finish day 24 --- aoc-2020-gleam/src/ext/setx.gleam | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'aoc-2020-gleam/src/ext/setx.gleam') 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) { -- cgit v1.2.3