Skip to content

Commit 8840592

Browse files
sportolpil
authored andcommitted
Use reverse and fold instead of append
1 parent 12fdf47 commit 8840592

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gleam/list.gleam

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,12 @@ pub fn combinations(items: List(a), by n: Int) -> List(List(a)) {
14741474
[x, ..xs] -> {
14751475
let first_combinations =
14761476
map(combinations(xs, n - 1), with: fn(com) { [x, ..com] })
1477-
append(first_combinations, combinations(xs, n))
1477+
|> reverse
1478+
fold(
1479+
first_combinations,
1480+
combinations(xs, n),
1481+
fn(c, acc) { [c, ..acc] },
1482+
)
14781483
}
14791484
}
14801485
}

0 commit comments

Comments
 (0)