diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/list.gleam | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 1fcd2d8..4745f43 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -1474,7 +1474,12 @@ pub fn combinations(items: List(a), by n: Int) -> List(List(a)) { [x, ..xs] -> { let first_combinations = map(combinations(xs, n - 1), with: fn(com) { [x, ..com] }) - append(first_combinations, combinations(xs, n)) + |> reverse + fold( + first_combinations, + combinations(xs, n), + fn(c, acc) { [c, ..acc] }, + ) } } } |