View Source Iter.Iterable protocol (iterex v0.1.1)
This is the main iterable protocol.
It is intentionally huge, however rte only function you have to implement is
next/1
, for the remainder you can rely on the default implementations from
Iter.Impl
unless your data structure can provide a more
efficient method of generating the correct answer.
Summary
Functions
Tests if every element in the iterable matches predicate
.
Tests if any element in the iterable matches predicate
.
Append an element onto the end of the iterable.
Returns the element index
items from the beginning of the iterator.
Creates an iterable that only emits elements for which fun
returns a new
value.
Creates an iterable that chunks into count
size elements, where each new
chunk starts step
elements into the enumerable.
Creates an iterable that chunks based on a chunk function.
Creates an iterable that iterates each iterable in an iterable.
Consumes the iterable, counting the number of iterations remaining.
Consumes the iterable, counting the number of elements for which fun
returns a truthy value.
Creates an iterable that cycles it's elements eternally.
Creates an iterable that only emits elements if they are different from the previous element.
Creates an iterable that only emits elements if they are different from the previous element.
Creates an iterable which drops the first how_many
elements.
Returns a new iterable with every nth
element in the iterable
dropped,
starting with the first element.
Drops elements at the beginning of the iterable
while predicate
returns a
truthy value.
Consumes the iterable and applies fun
to each element.
Determines if the iterable is empty.
Creates an iterable which drops elements for which predicate
doesn't return
a truthy value.
Searches for the first element in the iterable which matches predicate
.
Returns the index of the first element in the iterable which matches predicate
.
Returns the first non-falsy result of fun
.
Creates an iterable which works like map/2
but flattens nested iterables.
Creates an iterable which flattens nested iterables.
Creates a new iterable which places separator
between adjacent items of the original iterable.
Creates a new iterable which applies mapper
to each element and using it's
result as the new element value.
Creates a new iterable which applies mapper
on every nth
element of the
iterable, starting with the first element.
Returns the maximal element in the iterable
according to Erlang's term ordering.
Returns the maximal element in the iterable
as calculated by mapper
.
Is the element a member of the iterable?
Returns the minimal element in the iterable
according to Erlang's term ordering.
Returns the minimal element in the iterable
as calculated by mapper
.
Return the minimal and maximal element of the iterable.
Advance the iterable and return the next value.
Peeks at the first element of the iterable, without consuming it.
Peeks at the first n elements of the iterable, without consuming it.
Creates an iterable which prepends an element to the beginning of another iterable.
Creates an iterable starting at the same point, but stepping by step_size
each iteration.
Collects how_many
elements into a chunk and returns it as well as the
remaining iterable.
Creates an iterable which takes the first how_many
elements.
Creates an iterable which takes the last how_many
elements.
Creates an iterable which emits elements until predicate
returns false
.
Convert the iterable into a list.
Creates an iterable that returns only unique elements.
Creates an iterable which emits the current iteration count as well as the next value.
Zips corresponding elements from a number of iterables into an iterable of
results as computed by zipper
.
Types
@type element() :: Iter.element()
@type mapper() :: Iter.mapper()
@type predicate() :: Iter.predicate()
@type t() :: any()
Functions
Tests if every element in the iterable matches predicate
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Tests if any element in the iterable matches predicate
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Append an element onto the end of the iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec at(t(), non_neg_integer()) :: {:ok, non_neg_integer(), t()} | :done
Returns the element index
items from the beginning of the iterator.
Note that all preceding elements, as well as the returned element, will be consumed from the iterable.
Return values
{:ok, element, new_iterable}
- the next element and an updated iterable.:done
- the iterable was exhausted before the element was found.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that only emits elements for which fun
returns a new
value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec chunk_every(t(), pos_integer(), pos_integer(), t() | :discard) :: t()
Creates an iterable that chunks into count
size elements, where each new
chunk starts step
elements into the enumerable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec chunk_while( t(), acc, (element(), acc -> {:cont, chunk, acc} | {:cont, acc} | {:halt, acc}), (acc -> {:cont, chunk, acc} | {:cont, acc}) ) :: t() when acc: any(), chunk: any()
Creates an iterable that chunks based on a chunk function.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that iterates each iterable in an iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec count(t()) :: non_neg_integer()
Consumes the iterable, counting the number of iterations remaining.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec count(t(), (element() -> as_boolean(any()))) :: non_neg_integer()
Consumes the iterable, counting the number of elements for which fun
returns a truthy value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that cycles it's elements eternally.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that only emits elements if they are different from the previous element.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that only emits elements if they are different from the previous element.
The function fun
maps every element to a term which is used to determine if two elements are duplicates.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec drop(t(), non_neg_integer()) :: t()
Creates an iterable which drops the first how_many
elements.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec drop_every(t(), non_neg_integer()) :: t()
Returns a new iterable with every nth
element in the iterable
dropped,
starting with the first element.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Drops elements at the beginning of the iterable
while predicate
returns a
truthy value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Consumes the iterable and applies fun
to each element.
Primarily used for side-effects.
Always returns :done
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Determines if the iterable is empty.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which drops elements for which predicate
doesn't return
a truthy value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Searches for the first element in the iterable which matches predicate
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec find_index(t(), predicate()) :: {:ok, non_neg_integer(), t()} | :done
Returns the index of the first element in the iterable which matches predicate
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Returns the first non-falsy result of fun
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which works like map/2
but flattens nested iterables.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which flattens nested iterables.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates a new iterable which places separator
between adjacent items of the original iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates a new iterable which applies mapper
to each element and using it's
result as the new element value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec map_every(t(), non_neg_integer(), (element() -> new_element)) :: t() when new_element: any()
Creates a new iterable which applies mapper
on every nth
element of the
iterable, starting with the first element.
The first element is always mapped unless nth
is 0
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Returns the maximal element in the iterable
according to Erlang's term ordering.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec max_by(t(), (element() -> new_element), (new_element, new_element -> boolean())) :: {:ok, element()} | :done when new_element: element()
Returns the maximal element in the iterable
as calculated by mapper
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Is the element a member of the iterable?
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Returns the minimal element in the iterable
according to Erlang's term ordering.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec min_by(t(), (element() -> new_element), (new_element, new_element -> boolean())) :: {:ok, element()} | :done when new_element: element()
Returns the minimal element in the iterable
as calculated by mapper
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Return the minimal and maximal element of the iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Advance the iterable and return the next value.
This is the only required callback in the Iterable
protocol.
Return values
{:ok, element, new_iterable}
- returns the next element and an updated iterable.:done
- the iterable is exhausted.
@spec peek(t()) :: {:ok, element(), t()} | :done
@spec peek(t()) :: {:ok, [element()], non_neg_integer(), t()} | :done
Peeks at the first element of the iterable, without consuming it.
Return values
{:ok, element, new_iterable}
- the next element and an updated iterable.:done
- the iterable is exhausted.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Peeks at the first n elements of the iterable, without consuming it.
Return values
{:ok, [element], how_many, new_iterable}
- the peekable elements and an updated iterable. Note thathow_many
may not be the same as you asked for if the underlying iterable is exhausted.:done
- the iterable is exhausted.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which prepends an element to the beginning of another iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec step_by(t(), pos_integer()) :: t()
Creates an iterable starting at the same point, but stepping by step_size
each iteration.
The first element of the iterable will always be returned, regardless of the step given.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec take_chunk(t(), non_neg_integer()) :: {:ok, t(), t()} | {:done, t()}
Collects how_many
elements into a chunk and returns it as well as the
remaining iterable.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec take_head(t(), non_neg_integer()) :: t()
Creates an iterable which takes the first how_many
elements.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
@spec take_tail(t(), non_neg_integer()) :: t()
Creates an iterable which takes the last how_many
elements.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which emits elements until predicate
returns false
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Convert the iterable into a list.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable that returns only unique elements.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Creates an iterable which emits the current iteration count as well as the next value.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.
Zips corresponding elements from a number of iterables into an iterable of
results as computed by zipper
.
Optional callback
A default implementation of this function exists in the
Iter.Impl
module.You can add it to your protocol implementation by adding
use Iter.Impl
.