aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/gleam/list.gleam10
-rw-r--r--test/gleam/list_test.gleam14
3 files changed, 13 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66df392..14ff48c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@
- The `dynamic` module gains the `tuple3`, `tuple4`, `tuple5`, `tuple6`
functions and their typed equivalents `typed_tuple3`, `typed_tuple4`,
`typed_tuple5`, `typed_tuple6`.
-- The `list` module gains the `combinations_by`, `combinations_by_2`, `drop_while`, `map_fold`, `take_while`, `reduce`,
+- The `list` module gains the `combinations`, `combinations_by_2`, `drop_while`, `map_fold`, `take_while`, `reduce`,
`chunk`, `sized_chunk`, `last` and `scan` functions.
- The `iterator` module gains the `index`, `iterate`, `zip`, `scan`, `last`,
`take_while`, `drop_while`, `chunk`, `sized_chunk`, `intersperse`, `interleave`, `reduce`,
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 873f5ad..0622147 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1458,14 +1458,14 @@ pub fn last(list: List(a)) -> Result(a, Nil) {
/// ## Examples
///
/// ```
-/// > combinations_by([1, 2, 3], 2)
+/// > combinations([1, 2, 3], 2)
/// [[1, 2], [1, 3], [2, 3]]
///
-/// > combinations_by([1, 2, 3, 4], 3)
+/// > combinations([1, 2, 3, 4], 3)
/// [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
/// ```
///
-pub fn combinations_by(items: List(a), n: Int) -> List(List(a)) {
+pub fn combinations(items: List(a), by n: Int) -> List(List(a)) {
case n {
0 -> [[]]
_ ->
@@ -1473,8 +1473,8 @@ pub fn combinations_by(items: List(a), n: Int) -> List(List(a)) {
[] -> []
[x, ..xs] -> {
let first_combinations =
- map(combinations_by(xs, n - 1), with: fn(com) { [x, ..com] })
- append(first_combinations, combinations_by(xs, n))
+ map(combinations(xs, n - 1), with: fn(com) { [x, ..com] })
+ append(first_combinations, combinations(xs, n))
}
}
}
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam
index 294c9f4..ff812b6 100644
--- a/test/gleam/list_test.gleam
+++ b/test/gleam/list_test.gleam
@@ -654,23 +654,23 @@ pub fn last_test() {
|> should.equal(Ok(5))
}
-pub fn combinations_by_test() {
- list.combinations_by([1, 2, 3], 0)
+pub fn combinations_test() {
+ list.combinations([1, 2, 3], by: 0)
|> should.equal([[]])
- list.combinations_by([1, 2, 3], 1)
+ list.combinations([1, 2, 3], by: 1)
|> should.equal([[1], [2], [3]])
- list.combinations_by([1, 2, 3], 2)
+ list.combinations([1, 2, 3], by: 2)
|> should.equal([[1, 2], [1, 3], [2, 3]])
- list.combinations_by([1, 2, 3], 3)
+ list.combinations([1, 2, 3], by: 3)
|> should.equal([[1, 2, 3]])
- list.combinations_by([1, 2, 3], 4)
+ list.combinations([1, 2, 3], by: 4)
|> should.equal([])
- list.combinations_by([1, 2, 3, 4], 3)
+ list.combinations([1, 2, 3, 4], 3)
|> should.equal([[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]])
}