Skip to content

Commit

Permalink
deprecate concat
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored and lpil committed Oct 20, 2024
1 parent 5d7033c commit dd90ccf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/gleam/dynamic.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)]))
}
}
}
Expand Down Expand Up @@ -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)]))
}
}
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 6 additions & 5 deletions src/gleam/list.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1888,7 +1889,7 @@ pub fn permutations(list: List(a)) -> List(List(a)) {
|> permutations
|> map(fn(permutation) { [i, ..permutation] })
})
|> concat
|> flatten
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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]
}
Expand Down
8 changes: 4 additions & 4 deletions test/gleam/iterator_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn flat_map_test() {
subject
|> list.map(f)
|> list.map(iterator.to_list)
|> list.concat,
|> list.flatten,
)
}

Expand All @@ -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([], [])
Expand All @@ -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([[], []])
Expand All @@ -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([[], []])
Expand Down

0 comments on commit dd90ccf

Please sign in to comment.