diff options
author | Sebastian <s@porto5.com> | 2021-04-27 11:46:54 +1000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-04-29 20:24:23 +0100 |
commit | 747d13dcc84e64ffb23fbf958b7a279fa029dcb0 (patch) | |
tree | 0b84187d19ffc3f336b745602d7521b83f88ba94 | |
parent | 5240db2fc2e6ea7ed6577c1e6cc49d8c551aa2da (diff) | |
download | gleam_stdlib-747d13dcc84e64ffb23fbf958b7a279fa029dcb0.tar.gz gleam_stdlib-747d13dcc84e64ffb23fbf958b7a279fa029dcb0.zip |
Rename combination_by_2 to combination_pairs
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/gleam/list.gleam | 10 | ||||
-rw-r--r-- | test/gleam/list_test.gleam | 10 |
3 files changed, 11 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 14ff48c..4b7ef0d 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`, `combinations_by_2`, `drop_while`, `map_fold`, `take_while`, `reduce`, +- The `list` module gains the `combinations`, `combination_pairs`, `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 869fc10..6170496 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -1480,12 +1480,12 @@ pub fn combinations(items: List(a), by n: Int) -> List(List(a)) { } } -fn do_combinations_by_2(items: List(a)) -> List(List(tuple(a, a))) { +fn do_combination_pairs(items: List(a)) -> List(List(tuple(a, a))) { case items { [] -> [] [x, ..xs] -> { let first_combinations = map(xs, with: fn(other) { tuple(x, other) }) - [first_combinations, combinations_by_2(xs)] + [first_combinations, combination_pairs(xs)] } } } @@ -1495,11 +1495,11 @@ fn do_combinations_by_2(items: List(a)) -> List(List(tuple(a, a))) { /// ## Examples /// /// ``` -/// > combinations_by_2([1, 2, 3]) +/// > combination_pairs([1, 2, 3]) /// [tuple(1, 2), tuple(1, 3), tuple(2, 3)] /// ``` /// -pub fn combinations_by_2(items: List(a)) -> List(tuple(a, a)) { - do_combinations_by_2(items) +pub fn combination_pairs(items: List(a)) -> List(tuple(a, a)) { + do_combination_pairs(items) |> flatten } diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index ff812b6..16abd0a 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -674,17 +674,17 @@ pub fn combinations_test() { |> should.equal([[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]) } -pub fn combinations_by_2_test() { - list.combinations_by_2([1]) +pub fn combination_pairs_test() { + list.combination_pairs([1]) |> should.equal([]) - list.combinations_by_2([1, 2]) + list.combination_pairs([1, 2]) |> should.equal([tuple(1, 2)]) - list.combinations_by_2([1, 2, 3]) + list.combination_pairs([1, 2, 3]) |> should.equal([tuple(1, 2), tuple(1, 3), tuple(2, 3)]) - list.combinations_by_2([1, 2, 3, 4]) + list.combination_pairs([1, 2, 3, 4]) |> should.equal([ tuple(1, 2), tuple(1, 3), |