aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-08-26 00:51:54 +0200
committerLouis Pilfold <louis@lpil.uk>2023-09-04 12:50:50 +0100
commit9b3f2296ec5b1937abe618cc28716a30c712c20d (patch)
treec2276c76b90bb63b561c1d8f7870848a8333e112 /src
parent7eb79b56bef006957b597fc5ad277db539a87d69 (diff)
downloadgleam_stdlib-9b3f2296ec5b1937abe618cc28716a30c712c20d.tar.gz
gleam_stdlib-9b3f2296ec5b1937abe618cc28716a30c712c20d.zip
Rename `iterator.flatten` into `iterator.concat`
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 8ce7355..db57fea 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -413,11 +413,11 @@ pub fn append(to first: Iterator(a), suffix second: Iterator(a)) -> Iterator(a)
|> Iterator
}
-fn do_flatten(flattened: fn() -> Action(Iterator(a))) -> Action(a) {
+fn do_concat(flattened: fn() -> Action(Iterator(a))) -> Action(a) {
case flattened() {
Stop -> Stop
Continue(it, next_iterator) ->
- do_append(it.continuation, fn() { do_flatten(next_iterator) })
+ do_append(it.continuation, fn() { do_concat(next_iterator) })
}
}
@@ -431,13 +431,21 @@ fn do_flatten(flattened: fn() -> Action(Iterator(a))) -> Action(a) {
/// ```gleam
/// > from_list([[1, 2], [3, 4]])
/// > |> map(from_list)
-/// > |> flatten
+/// > |> from_list
+/// > |> concat
/// > |> to_list
/// [1, 2, 3, 4]
/// ```
///
+pub fn concat(iterator: Iterator(Iterator(a))) -> Iterator(a) {
+ fn() { do_concat(iterator.continuation) }
+ |> Iterator
+}
+
+// TODO: Add deprecation attribute and then remove later.
+/// This function is deprecated, see `concat` instead.
pub fn flatten(iterator: Iterator(Iterator(a))) -> Iterator(a) {
- fn() { do_flatten(iterator.continuation) }
+ fn() { do_concat(iterator.continuation) }
|> Iterator
}
@@ -466,7 +474,7 @@ pub fn flat_map(
) -> Iterator(b) {
iterator
|> map(f)
- |> flatten
+ |> concat
}
fn do_filter(
@@ -525,7 +533,7 @@ pub fn filter(
///
pub fn cycle(iterator: Iterator(a)) -> Iterator(a) {
repeat(iterator)
- |> flatten
+ |> concat
}
/// Creates an iterator of ints, starting at a given start int and stepping by