aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKayla Washburn <mckayla@hey.com>2023-07-13 07:34:25 -0600
committerGitHub <noreply@github.com>2023-07-13 14:34:25 +0100
commit55e7b16fefdcc477719dda3e606828e154c35bdf (patch)
tree54ac4edb4a34a2126f964d55ce1e2bea9923d180 /src
parent682d9e03ba2847c63b9f3882bb3d743b67552def (diff)
downloadgleam_stdlib-55e7b16fefdcc477719dda3e606828e154c35bdf.tar.gz
gleam_stdlib-55e7b16fefdcc477719dda3e606828e154c35bdf.zip
rename `list.flatten` to `list.concat` (#477)
Diffstat (limited to 'src')
-rw-r--r--src/gleam/dynamic.gleam16
-rw-r--r--src/gleam/list.gleam24
2 files changed, 20 insertions, 20 deletions
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam
index 86055a0..f6b1717 100644
--- a/src/gleam/dynamic.gleam
+++ b/src/gleam/dynamic.gleam
@@ -1190,7 +1190,7 @@ pub fn decode2(
fn(value) {
case t1(value), t2(value) {
Ok(a), Ok(b) -> Ok(constructor(a, b))
- a, b -> Error(list.flatten([all_errors(a), all_errors(b)]))
+ a, b -> Error(list.concat([all_errors(a), all_errors(b)]))
}
}
}
@@ -1224,7 +1224,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.flatten([all_errors(a), all_errors(b), all_errors(c)]))
+ Error(list.concat([all_errors(a), all_errors(b), all_errors(c)]))
}
}
}
@@ -1271,7 +1271,7 @@ pub fn decode4(
case t1(x), t2(x), t3(x), t4(x) {
Ok(a), Ok(b), Ok(c), Ok(d) -> Ok(constructor(a, b, c, d))
a, b, c, d ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
@@ -1326,7 +1326,7 @@ pub fn decode5(
case t1(x), t2(x), t3(x), t4(x), t5(x) {
Ok(a), Ok(b), Ok(c), Ok(d), Ok(e) -> Ok(constructor(a, b, c, d, e))
a, b, c, d, e ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
@@ -1386,7 +1386,7 @@ pub fn decode6(
Ok(a), Ok(b), Ok(c), Ok(d), Ok(e), Ok(f) ->
Ok(constructor(a, b, c, d, e, f))
a, b, c, d, e, f ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
@@ -1450,7 +1450,7 @@ pub fn decode7(
Ok(a), Ok(b), Ok(c), Ok(d), Ok(e), Ok(f), Ok(g) ->
Ok(constructor(a, b, c, d, e, f, g))
a, b, c, d, e, f, g ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
@@ -1518,7 +1518,7 @@ pub fn decode8(
Ok(a), Ok(b), Ok(c), Ok(d), Ok(e), Ok(f), Ok(g), Ok(h) ->
Ok(constructor(a, b, c, d, e, f, g, h))
a, b, c, d, e, f, g, h ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
@@ -1590,7 +1590,7 @@ pub fn decode9(
Ok(a), Ok(b), Ok(c), Ok(d), Ok(e), Ok(f), Ok(g), Ok(h), Ok(i) ->
Ok(constructor(a, b, c, d, e, f, g, h, i))
a, b, c, d, e, f, g, h, i ->
- Error(list.flatten([
+ Error(list.concat([
all_errors(a),
all_errors(b),
all_errors(c),
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index b1acb74..ed1d718 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -660,30 +660,30 @@ fn reverse_and_prepend(list prefix: List(a), to suffix: List(a)) -> List(a) {
}
}
-fn do_flatten(lists: List(List(a)), acc: List(a)) -> List(a) {
+fn do_concat(lists: List(List(a)), acc: List(a)) -> List(a) {
case lists {
[] -> reverse(acc)
[list, ..further_lists] ->
- do_flatten(further_lists, reverse_and_prepend(list: list, to: acc))
+ do_concat(further_lists, reverse_and_prepend(list: list, to: acc))
}
}
-/// Flattens a list of lists into a single list.
+/// Joins a list of lists into a single list.
///
/// This function traverses all elements twice.
///
/// ## Examples
///
/// ```gleam
-/// > flatten([[1], [2, 3], []])
+/// > concat([[1], [2, 3], []])
/// [1, 2, 3]
/// ```
///
-pub fn flatten(lists: List(List(a))) -> List(a) {
- do_flatten(lists, [])
+pub fn concat(lists: List(List(a))) -> List(a) {
+ do_concat(lists, [])
}
-/// Maps the list with the given function and then flattens it.
+/// Maps the list with the given function into a list of lists, and then flattens it.
///
/// ## Examples
///
@@ -694,7 +694,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)
- |> flatten
+ |> concat
}
/// Reduces a list of elements into a single value by calling a given function
@@ -1684,7 +1684,7 @@ pub fn permutations(l: List(a)) -> List(List(a)) {
|> permutations
|> map(fn(permutation) { [i, ..permutation] })
})
- |> flatten
+ |> concat
}
}
@@ -2012,7 +2012,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)
- |> flatten
+ |> concat
}
/// Make a list alternating the elements from the given lists
@@ -2026,7 +2026,7 @@ pub fn combination_pairs(items: List(a)) -> List(#(a, a)) {
///
pub fn interleave(list: List(List(a))) -> List(a) {
transpose(list)
- |> flatten
+ |> concat
}
/// Transpose rows and columns of the list of lists.
@@ -2058,7 +2058,7 @@ pub fn transpose(list_of_list: List(List(a))) -> List(List(a)) {
let firsts =
rows
|> map(take_first)
- |> flatten
+ |> concat
let rest = transpose(map(rows, drop(_, 1)))
[firsts, ..rest]
}