aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian <s@porto5.com>2021-04-27 15:18:52 +1000
committerLouis Pilfold <louis@lpil.uk>2021-04-29 20:24:23 +0100
commit88405921248b94c360e91840fe7ebfe98c4d01af (patch)
tree239867ee453e9d73277149ad6cfd328aaab8214a /src
parent12fdf47b0e5e912ef771f1860cedca8b24477b44 (diff)
downloadgleam_stdlib-88405921248b94c360e91840fe7ebfe98c4d01af.tar.gz
gleam_stdlib-88405921248b94c360e91840fe7ebfe98c4d01af.zip
Use reverse and fold instead of append
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam7
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] },
+ )
}
}
}