diff options
-rw-r--r-- | src/gleam/iterator.gleam | 21 | ||||
-rw-r--r-- | test/gleam/iterator_test.gleam | 1 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index 8a4410d..efde4f5 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -2,24 +2,25 @@ import gleam/list // Internal private representation of an Iterator type Action(element) { - // Improper dancing in the middle of the street - // Improper dancing in the middle of the street - // Improper dancing in the middle of the street - // Somebody better notify the chief of police Stop Continue(element, fn() -> Action(element)) } -// Yes! -// Wrapper to hide the internal representation +/// An iterator is a lazily evaluated sequence of element. +/// +/// Iterators are useful when working with collections that are too large to +/// fit in memory (or those that are infinite in size) as they only require the +/// elements currently being processed to be in memory. +/// +/// As a lazy data structure no work is done when an iterator is filters, +/// mapped, etc, instead a new iterator is returned with these transformations +/// applied to the stream. Once the stream has all the required transformations +/// applied it can be evaluated using functions such as `fold` and `take`. +/// pub opaque type Iterator(element) { Iterator(thunk: fn() -> Action(element)) } -pub fn identity(x) { - x -} - // Public API for iteration pub type Step(element, acc) { Next(element, acc) diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam index ec1eac3..015d3b2 100644 --- a/test/gleam/iterator_test.gleam +++ b/test/gleam/iterator_test.gleam @@ -2,7 +2,6 @@ import gleam/should import gleam/iterator import gleam/list -// TODO: Property tests // a |> from_list |> to_list == a pub fn to_from_list_test() { let test = fn(subject) { |