diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-08-26 13:50:42 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-09-04 12:50:50 +0100 |
commit | bb7798efd8b75c8770d3b17d0bd4683c2abd0ea0 (patch) | |
tree | 8556b63f6e96d3862e0388ff078b4487b69057c8 /src | |
parent | 5832ccd7189549dbb4ae4fb6b6cd249883446454 (diff) | |
download | gleam_stdlib-bb7798efd8b75c8770d3b17d0bd4683c2abd0ea0.tar.gz gleam_stdlib-bb7798efd8b75c8770d3b17d0bd4683c2abd0ea0.zip |
Change `iterator.flatten`'s type
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/iterator.gleam | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index db57fea..f4421a3 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -421,7 +421,7 @@ fn do_concat(flattened: fn() -> Action(Iterator(a))) -> Action(a) { } } -/// Flattens an iterator of iterators, creating a new iterator. +/// Joins an iterator of iterators into a single iterator. /// /// This function does not evaluate the elements of the iterator, the /// computation is performed when the iterator is later run. @@ -442,11 +442,23 @@ pub fn concat(iterator: Iterator(Iterator(a))) -> Iterator(a) { |> 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_concat(iterator.continuation) } - |> Iterator +/// Joins a list of iterators into a single iterator. +/// +/// This function does not evaluate the elements of the iterator, the +/// computation is performed when the iterator is later run. +/// +/// ## Examples +/// +/// ```gleam +/// > [[1, 2], [3, 4]] +/// > |> map(from_list) +/// > |> flatten +/// > |> to_list +/// [1, 2, 3, 4] +/// ``` +/// +pub fn flatten(iterators: List(Iterator(a))) -> Iterator(a) { + concat(from_list(iterators)) } /// Creates an iterator from an existing iterator and a transformation function. |