diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2024-10-20 13:43:15 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-10-20 20:07:28 +0100 |
commit | dd90ccf53a028bda83e7f6dcdb8bdb002ed168bf (patch) | |
tree | 5db0e265ef5c2fcacc135cacb58c036fa429800c | |
parent | 5d7033c845469f9c70a6b877670319ae27c7b51a (diff) | |
download | gleam_stdlib-dd90ccf53a028bda83e7f6dcdb8bdb002ed168bf.tar.gz gleam_stdlib-dd90ccf53a028bda83e7f6dcdb8bdb002ed168bf.zip |
deprecate concat
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/gleam/dynamic.gleam | 16 | ||||
-rw-r--r-- | src/gleam/list.gleam | 11 | ||||
-rw-r--r-- | test/gleam/iterator_test.gleam | 8 |
4 files changed, 20 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c48880a..d734bbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - The `float` modeule gains the `to_precision` function. - The `try_fold` function in the `iterator` module is now tail recursive. - The performance of many functions in the `string` module has been improved. +- The `concat` function in the `list` module has been deprecated in favour of + `flatten`. ## v0.40.0 - 2024-08-19 diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam index 5b3bb46..f142034 100644 --- a/src/gleam/dynamic.gleam +++ b/src/gleam/dynamic.gleam @@ -1087,7 +1087,7 @@ pub fn decode2( fn(value) { case t1(value), t2(value) { Ok(a), Ok(b) -> Ok(constructor(a, b)) - a, b -> Error(list.concat([all_errors(a), all_errors(b)])) + a, b -> Error(list.flatten([all_errors(a), all_errors(b)])) } } } @@ -1121,7 +1121,7 @@ pub fn decode3( case t1(value), t2(value), t3(value) { Ok(a), Ok(b), Ok(c) -> Ok(constructor(a, b, c)) a, b, c -> - Error(list.concat([all_errors(a), all_errors(b), all_errors(c)])) + Error(list.flatten([all_errors(a), all_errors(b), all_errors(c)])) } } } @@ -1169,7 +1169,7 @@ pub fn decode4( Ok(a), Ok(b), Ok(c), Ok(d) -> Ok(constructor(a, b, c, d)) a, b, c, d -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), @@ -1226,7 +1226,7 @@ pub fn decode5( Ok(a), Ok(b), Ok(c), Ok(d), Ok(e) -> Ok(constructor(a, b, c, d, e)) a, b, c, d, e -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), @@ -1288,7 +1288,7 @@ pub fn decode6( Ok(constructor(a, b, c, d, e, f)) a, b, c, d, e, f -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), @@ -1354,7 +1354,7 @@ pub fn decode7( Ok(constructor(a, b, c, d, e, f, g)) a, b, c, d, e, f, g -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), @@ -1424,7 +1424,7 @@ pub fn decode8( Ok(constructor(a, b, c, d, e, f, g, h)) a, b, c, d, e, f, g, h -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), @@ -1498,7 +1498,7 @@ pub fn decode9( Ok(constructor(a, b, c, d, e, f, g, h, i)) a, b, c, d, e, f, g, h, i -> Error( - list.concat([ + list.flatten([ all_errors(a), all_errors(b), all_errors(c), diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index f0248e7..c363cda 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -699,6 +699,7 @@ fn do_concat(lists: List(List(a)), acc: List(a)) -> List(a) { /// // -> [1, 2, 3] /// ``` /// +@deprecated("Use `list.flatten` instead.") pub fn concat(lists: List(List(a))) -> List(a) { do_concat(lists, []) } @@ -730,7 +731,7 @@ pub fn flatten(lists: List(List(a))) -> List(a) { /// pub fn flat_map(over list: List(a), with fun: fn(a) -> List(b)) -> List(b) { map(list, fun) - |> concat + |> flatten } /// Reduces a list of elements into a single value by calling a given function @@ -1888,7 +1889,7 @@ pub fn permutations(list: List(a)) -> List(List(a)) { |> permutations |> map(fn(permutation) { [i, ..permutation] }) }) - |> concat + |> flatten } } @@ -2216,7 +2217,7 @@ fn do_combination_pairs(items: List(a)) -> List(List(#(a, a))) { /// pub fn combination_pairs(items: List(a)) -> List(#(a, a)) { do_combination_pairs(items) - |> concat + |> flatten } /// Make a list alternating the elements from the given lists @@ -2230,7 +2231,7 @@ pub fn combination_pairs(items: List(a)) -> List(#(a, a)) { /// pub fn interleave(list: List(List(a))) -> List(a) { transpose(list) - |> concat + |> flatten } /// Transpose rows and columns of the list of lists. @@ -2262,7 +2263,7 @@ pub fn transpose(list_of_list: List(List(a))) -> List(List(a)) { let firsts = rows |> map(take_first) - |> concat + |> flatten let rest = transpose(map(rows, drop(_, 1))) [firsts, ..rest] } diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam index 6ae1d4c..f774a62 100644 --- a/test/gleam/iterator_test.gleam +++ b/test/gleam/iterator_test.gleam @@ -207,7 +207,7 @@ pub fn flat_map_test() { subject |> list.map(f) |> list.map(iterator.to_list) - |> list.concat, + |> list.flatten, ) } @@ -225,7 +225,7 @@ pub fn append_test() { |> iterator.from_list |> iterator.append(iterator.from_list(right)) |> iterator.to_list - |> should.equal(list.concat([left, right])) + |> should.equal(list.flatten([left, right])) } testcase([], []) @@ -241,7 +241,7 @@ pub fn flatten_test() { |> iterator.from_list |> iterator.flatten |> iterator.to_list - |> should.equal(list.concat(lists)) + |> should.equal(list.flatten(lists)) } testcase([[], []]) @@ -256,7 +256,7 @@ pub fn concat_test() { |> list.map(iterator.from_list) |> iterator.concat |> iterator.to_list - |> should.equal(list.concat(lists)) + |> should.equal(list.flatten(lists)) } testcase([[], []]) |