Iterator
Enums
enum Step [a : Type]
SourceDefinitions
def
append
[aef1ref2]
(
iter1 :
Iterator[a, ef1, r]
iter2 :
Iterator[a, ef2, r]
)
: Iterator[a, ef1 + ef2, r]
\ Pure
Returns iterB
appended to (the end of) iterA
.
Does not consume any elements from either iterator.
The original iterators iterA
and iterB
should not be reused.
def
cons
[aefr]
(
x :
a
iter :
Iterator[a, ef, r]
)
: Iterator[a, ef, r]
\ r
Returns an iterator with the element x
appended to the
front of iterator iter
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
drop
[aefr]
(
n :
Int32
iter :
Iterator[a, ef, r]
)
: Iterator[a, ef + r, r]
\ r
Returns iter
without the first n
elements.
Returns an empty iterator if n
is larger than the number of elements in iter
.
Returns iter
if n < 0
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
dropWhile
[aef2ef1r]
(
f :
a -> Bool \ ef2
iter :
Iterator[a, ef1, r]
)
: Iterator[a, r + ef1 + ef2, r]
\ r
Returns iter
without the longest prefix that satisfies the predicate f
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
empty
[ra]
(
rc :
Region[r]
)
: Iterator[a, r, r]
\ Pure
Returns an empty iterator.
def
enumerator
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Iterator[(Int32, a), ef + r, r]
\ r
Alias for zipWithIndex
.
def
filter
[aef2ef1r]
(
f :
a -> Bool \ ef2
iter :
Iterator[a, ef1, r]
)
: Iterator[a, ef1 + ef2, r]
\ Pure
Returns an iterator with every element of the iterator iter
that
satisfies the predicate f
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
filterMap
[aef2bef1r]
(
f :
a -> Option[b] \ ef2
iter :
Iterator[a, ef1, r]
)
: Iterator[b, ef1 + ef2, r]
\ Pure
Returns an iterator with every element of the iterator iter
that
produces Some(_)
the from the function f
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
flatMap
[aef3bef2ref1]
(
f :
a -> Iterator[b, ef2, r] \ ef3
ma :
Iterator[a, ef1, r]
)
: Iterator[b, ef3 + ef2 + r + ef1, r]
\ r
Returns the result of applying f
to every element in iter
and concatenating the results.
Does not consume any elements from the iterator.
Currently f
has to generate an iterator with region r
.
def
flatten
[aef1ref2]
(
iter :
Iterator[Iterator[a, ef1, r], ef2, r]
)
: Iterator[a, r + ef1 + ef2, r]
\ r
Returns the concatenation of the nested iterators in iter
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
foldLeft
[baef2ef1r]
(
f :
b -> (a -> b \ ef2)
s :
b
iter :
Iterator[a, ef1, r]
)
: b
\ ef1 + ef2 + r
Applies f
to a start value s
and all elements in iter
going from left to right.
That is, the result is of the form: f(...f(f(s, x1), x2)..., xn)
.
Consumes the entire iterator.
def
foldMap
[aef2bef1r]
(
f :
a -> b \ ef2
iter :
Iterator[a, ef1, r]
)
: b
\ ef1 + ef2 + r
with
Monoid[b]
Returns the result of mapping each element and combining the results.
def
foldRight
[abef2ef1r]
(
f :
a -> (b -> b \ ef2)
s :
b
iter :
Iterator[a, ef1, r]
)
: b
\ ef1 + ef2 + r
Applies f
to a start value s
and all elements in iter
going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, s))...)
.
Consumes the entire iterator.
def
foldRightWithCont
[aefrb]
(
f :
a -> ((Unit -> b \ ef + r) -> b \ ef)
z :
b
iter :
Iterator[a, ef, r]
)
: b
\ ef + r
Applies f
to a start value z
and all elements in iter
going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, z))...)
.
A foldRightWithCont
allows early termination by not calling the continuation.
Consumes the entire iterator.
def
forEach
[aef2ef1r]
(
f :
a -> Unit \ ef2
iter :
Iterator[a, ef1, r]
)
: Unit
\ ef1 + ef2 + r
Applies f
to every element of iter
.
Consumes the entire iterator.
def
forEachWithIndex
[aef2ef1r]
(
f :
Int32 -> (a -> Unit \ ef2)
iter :
Iterator[a, ef1, r]
)
: Unit
\ ef1 + ef2 + r
Applies f
to every element of iter
along with that element's index.
Consumes the entire iterator.
def
intercalate
[taefr]
(
sep :
t[a]
iter :
Iterator[Iterator[a, ef, r], ef, r]
)
: Iterator[a, ef + r, r]
\ r
with
Foldable[t]
Returns the concatenation of the elements in iter
with the elements of sep
inserted between every two adjacent elements.
That is, returns b1 :: a1 ... an :: b2 :: ... bn-1 :: a1 :: ... :: an :: bn :: Nil
.
Does not consume any elements from either iterator.
The original iterators sep
and iter
should not be reused.
def
intersperse
[aefr]
(
sep :
a
iter :
Iterator[a, ef, r]
)
: Iterator[a, ef + r, r]
\ r
Returns an iterator with a
inserted between every of iter
.
Does not consume any elements from the iterator.
def
iterate
[refa]
(
rc :
Region[r]
f :
Unit -> Option[a] \ ef
)
: Iterator[a, ef, r]
\ Pure
Returns an iterator built with the stepper function f
.
def
join
[aefr]
(
sep :
String
iter :
Iterator[a, ef, r]
)
: String
\ ef + r
with
ToString[a]
Returns the concatenation of the string representation
of each element in iter
with sep
inserted between each element.
Consumes the entire iterator.
def
joinWith
[aef2ef1r]
(
f :
a -> String \ ef2
sep :
String
iter :
Iterator[a, ef1, r]
)
: String
\ ef1 + ef2 + r
Returns the concatenation of the string representation
of each element in iter
according to f
with sep
inserted between each element.
Consumes the entire iterator.
def
map
[aef2bef1r]
(
f :
a -> b \ ef2
iter :
Iterator[a, ef1, r]
)
: Iterator[b, ef1 + ef2, r]
\ Pure
Returns an iterator with every f
lazily applied to each element in iter
.
Does not consume any elements from the iterator.
def
mapWithIndex
[aef2bef1r]
(
f :
Int32 -> (a -> b \ ef2)
iter :
Iterator[a, ef1, r]
)
: Iterator[b, ef1 + ef2, r]
\ r
Returns an iterator with every f
lazily applied to each element in iter
together with its index.
Does not consume any elements from the iterator.
def
next
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Option[a]
\ ef + r
Returns Some(x)
if iter
is not empty. Returns None
otherwise.
Consumes the head element of iter
.
def
range
[r]
(
rc :
Region[r]
b :
Int32
e :
Int32
)
: Iterator[Int32, r, r]
\ r
Returns an iterator of all integers between b
(inclusive) and e
(exclusive).
Returns an empty iterator if b >= e
.
def
reduceLeft
[aef2ef1r]
(
f :
a -> (a -> a \ ef2)
iter :
Iterator[a, ef1, r]
)
: Option[a]
\ ef1 + ef2 + r
Applies f
to all elements in iter
going from left to right until a single value v
is obtained. Returns Some(v)
.
That is, the result is of the form: Some(f(...f(f(x1, x2), x3)..., xn))
Returns None
if iter
is empty.
Consumes the entire iterator.
def
repeat
[ra]
(
rc :
Region[r]
n :
Int32
x :
a
)
: Iterator[a, r, r]
\ r
Returns an iterator over an iterable with the element x
repeated n
times.
Returns an empty iterator if n < 0
.
def
replace
[aefr]
(
from :
{ from = a }
to :
{ to = a }
iter :
Iterator[a, ef, r]
)
: Iterator[a, ef, r]
\ Pure
with
Eq[a]
Returns an iterator with every occurrence of from
replaced by to
in iter
.
Does not consume any elements from the iterator.
def
singleton
[ra]
(
rc :
Region[r]
x :
a
)
: Iterator[a, r, r]
\ r
Returns an iterator containing only a single element, x
.
def
sum
[efr]
(
iter :
Iterator[Int32, ef, r]
)
: Int32
\ ef + r
Returns the sum of all elements in the iterator iter
.
Consumes the entire iterator.
def
sumWith
[aef2ef1r]
(
f :
a -> Int32 \ ef2
iter :
Iterator[a, ef1, r]
)
: Int32
\ ef1 + ef2 + r
Returns the sum of all elements in the iterator iter
according to the function f
.
Consumes the entire iterator.
def
take
[aefr]
(
n :
Int32
iter :
Iterator[a, ef, r]
)
: Iterator[a, ef + r, r]
\ r
Returns iter
with the first n
elements.
Returns iter
if n
is larger than the number of elements in iter
.
Returns an empty iterator if n < 0
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
takeWhile
[aef2ef1r]
(
f :
a -> Bool \ ef2
iter :
Iterator[a, ef1, r]
)
: Iterator[a, ef1 + ef2, r]
\ Pure
Returns the longest prefix of iter
that satisfies the predicate f
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.
def
toArray
[r1aefr2]
(
rc :
Region[r1]
iter :
Iterator[a, ef, r2]
)
: Array[a, r1]
\ ef + r2 + r1
Returns the contents of iter
as an array.
Consumes the entire iterator.
def
toChain
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Chain[a]
\ ef + r
Returns the contents of iter
as a chain.
Consumes the entire iterator.
def
toList
[aefr]
(
iter :
Iterator[a, ef, r]
)
: List[a]
\ ef + r
Returns the contents of iter
as a list.
Consumes the entire iterator.
def
toMap
[kvefr]
(
iter :
Iterator[(k, v), ef, r]
)
: Map[k, v]
\ ef + r
with
Order[k]
Returns the contents of iter
as a map.
Consumes the entire iterator.
def
toMutDeque
[r1aefr2]
(
rc :
Region[r1]
iter :
Iterator[a, ef, r2]
)
: MutDeque[a, r1]
\ ef + r2 + r1
Returns the contents of iter
as a MutDeque.
Consumes the entire iterator.
def
toNec
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Option[Nec[a]]
\ ef + r
Returns the contents of iter
as a Nec.
Consumes the entire iterator.
def
toNel
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Option[Nel[a]]
\ ef + r
Returns the contents of iter
as a Some(Nel)
if iter
is not empty. Returns None otherwise.
Consumes the entire iterator.
def
toSet
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Set[a]
\ ef + r
with
Order[a]
Returns the contents of iter
as a set. Consumes the entire iterator.
def
toVector
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Vector[a]
\ ef + r
Returns the contents of iter
as an array.
Consumes the entire iterator.
def
unfoldWithOk
[refea]
(
rc :
Region[r]
f :
Unit -> Result[e, a] \ ef
)
: Iterator[a, ef, r]
\ Pure
Returns an iterator over the results of f
.
If f
returns Ok(x)
, then the next element is x
.
If f
returns Err(e)
, then the iterator is depleted.
def
zip
[aef1r1bef2r2]
(
iterA :
Iterator[a, ef1, r1]
iterB :
Iterator[b, ef2, r2]
)
: Iterator[(a, b), r2 + ef1 + ef2, r1]
\ Pure
Returns an iterator where the element at index i
is (a, b)
where
a
is the element at index i
in iterA
and b
is the element at index i
in iterB
.
Does not consume any elements from either iterator.
If either iterA
or iterB
is depleted, then no further elements are added to the resulting iterator.
The original iterators iterA
and iterB
should not be reused.
An iterator should never be zipped with itself.
def
zipWith
[abef3cef1r1ef2r2]
(
f :
a -> (b -> c \ ef3)
iterA :
Iterator[a, ef1, r1]
iterB :
Iterator[b, ef2, r2]
)
: Iterator[c, ef3 + ef1 + ef2 + r2, r1]
\ Pure
Returns an iterator where the element at index i
is f(a, b)
where
a
is the element at index i
in iterA
and b
is the element at index i
in iterB
.
Does not consume any elements from either iterator.
If either iterA
or iterB
becomes depleted, then no further elements are added to the resulting list.
The original iterators iterA
and iterB
should not be reused.
An iterator should never be zipped with itself.
def
zipWithIndex
[aefr]
(
iter :
Iterator[a, ef, r]
)
: Iterator[(Int32, a), ef + r, r]
\ r
Returns an iterator where the element at index i
is (a, i)
where
a
is the element at index i
in iter
.
Does not consume any elements from the iterator.
The original iterator iter
should not be reused.