diff options
author | Louis Pilfold <louis@lpil.uk> | 2023-07-27 15:20:34 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-07-27 15:25:29 +0100 |
commit | dfdbc60ba3e718c1b4805b06d7c845b16bf359dc (patch) | |
tree | 673dbe44be5db134f2d45dd8123bf32cb50d2116 /src | |
parent | 725edc71cd5f2e2162911faeaaa825a4776885b2 (diff) | |
download | gleam_stdlib-dfdbc60ba3e718c1b4805b06d7c845b16bf359dc.tar.gz gleam_stdlib-dfdbc60ba3e718c1b4805b06d7c845b16bf359dc.zip |
yield documentation
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/iterator.gleam | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index 6a16ad8..8ce7355 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -1441,6 +1441,21 @@ pub fn each(over iterator: Iterator(a), with f: fn(a) -> b) -> Nil { |> run } +/// Add a new element to the start of an iterator. +/// +/// This function is for use with `use` expressions, to replicate the behaviour +/// of the `yield` keyword found in other languages. +/// +/// ## Examples +/// +/// ```gleam +/// > use <- iterator.yield(1) +/// > use <- iterator.yield(2) +/// > use <- iterator.yield(3) +/// > iterator.empty() +/// iterator.from_list([1, 2, 3]) +/// ``` +/// pub fn yield(element: a, next: fn() -> Iterator(a)) -> Iterator(a) { Iterator(fn() { Continue(element, next().continuation) }) } |