diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-08-26 00:51:54 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-09-04 12:50:50 +0100 |
commit | 9b3f2296ec5b1937abe618cc28716a30c712c20d (patch) | |
tree | c2276c76b90bb63b561c1d8f7870848a8333e112 /src | |
parent | 7eb79b56bef006957b597fc5ad277db539a87d69 (diff) | |
download | gleam_stdlib-9b3f2296ec5b1937abe618cc28716a30c712c20d.tar.gz gleam_stdlib-9b3f2296ec5b1937abe618cc28716a30c712c20d.zip |
Rename `iterator.flatten` into `iterator.concat`
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/iterator.gleam | 20 |
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 |