aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/ext/setx.gleam
blob: 68d185aaccaebfdeb3f2e2fddb52e999d87d65a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gleam/list
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
  |> set.to_list
  |> iter.from_list
  |> iterx.count(satisfying: predicate)
}

pub fn map(set: Set(a), with fun: fn(a) -> b) -> Set(b) {
  set
  |> set.to_list
  |> list.map(with: fun)
  |> set.from_list
}