From dfdbc60ba3e718c1b4805b06d7c845b16bf359dc Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 27 Jul 2023 15:20:34 +0100 Subject: yield documentation --- src/gleam/iterator.gleam | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') 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) }) } -- cgit v1.2.3