Skip to content

Commit 5da48e5

Browse files
committed
Use built-in list.partition
1 parent bdb47a7 commit 5da48e5

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

src/aoc_2024/day_5.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn fix_order_rec(todos: List(#(Int, Set(Int))), acc: List(Int)) -> List(Int) {
9898
True -> acc
9999
False -> {
100100
let #(usable, rest) =
101-
extra.list_partition(todos, fn(todo_) { set.is_empty(todo_.1) })
101+
list.partition(todos, fn(todo_) { set.is_empty(todo_.1) })
102102
let usable_pages: List(Int) = usable |> list.map(fn(todo_) { todo_.0 })
103103
let cleaned_rest: List(#(Int, Set(Int))) =
104104
rest

src/extra.gleam

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,3 @@ pub fn strip_left(from input: String, remove prefix: String) -> String {
6363
False -> input
6464
}
6565
}
66-
67-
/// Splits list into a #(good, bad) based on a predicate (true, false)
68-
pub fn list_partition(xs: List(a), pred: fn(a) -> Bool) -> #(List(a), List(a)) {
69-
let #(good_rev, bad_rev) =
70-
list.fold(xs, #([], []), fn(acc, x) {
71-
case pred(x) {
72-
True -> #([x, ..acc.0], acc.1)
73-
False -> #(acc.0, [x, ..acc.1])
74-
}
75-
})
76-
#(list.reverse(good_rev), list.reverse(bad_rev))
77-
}

0 commit comments

Comments
 (0)