Iterex is a library that provides external iterators for Elixir collections.
Iterators provide the flexibility of Enum
with the laziness of Stream
and the ability to pause and resume iteration.
The Iter
module provides the public interface to working with iterators, which wraps an Iter.Iterable
(to make it easier to pattern match, etc). You'll find most of the functions you'd want from Stream
and Enum
provided by this module, but often with different return values to enable you to resume iteration where possible. The Enumerable
and Collectable
protocols have been implemented for Iter
so you can use them as drop in replacements for other collection types where needed.
Some differences from Enum
and Stream
:
Iter.next/1
- the core advantage of iterators over streams. Allows you to retrieve the next element from an iterator and a new iterator.Iter.prepend/2
,Iter.append/2
andIter.peek/1..2
- iterators can be easily composed allowing features that might otherwise breakStream
semantics.
See the documentation on hexdocs for more information.
Thanks to Alembic Pty Ltd for sponsoring a portion of this project's development.
The package can be installed by adding iterex
to your list of dependencies in mix.exs
:
def deps do
[
{:iterex, "~> 0.1.0"}
]
end
- To contribute updates, fixes or new features please fork and open a pull-request against
main
. - Please use conventional commits - this allows us to dynamically generate the changelog.
iterex
is licensed under the terms of the MIT license. See the LICENSE
file in this repository
for details.