There's synchronous and asynchronous ops, but all of them has the same interface. Simple and easy.
Returns an array with all iterator values.
Warning: If iterator is infinite it never returns a value and, if synchronous operation it would be stop main thread.
array() -> return [x
1, ..., x
i]
Receives a positive integer named n and returns a value in the n position.
If iterator breaks before n position, return undefined.
at(n) -> return x
n
Receives n iterators and returns an iterator. This one emit all values of each iterator in order of the arguments insertion, starting by the original iterator.
For example:
numbers -> 0, 1, 2, 3, 4, 5
chars -> a, b, c, d, e, f
concat(numbers, chars) -> 0, 1, 2, 3, 4, 5, a, b, c, d, e, f
concat(it
1, ..., it
n) -> yield x
ni
Receives an integer that represents how many values do you want to skip and returns the same iterator but with the dropped values.
drop(n) -> yield x
i > n
Work as Array.prototype.every
.
Work as Array.prototype.filter
.
Work as Array.prototype.find
.
NOTE: Returns a Iterator with one or no value.
Returns first iterator value.
first() -> return x
0
In the case you have an iterators of iterators and you want to flatten, this is your op.
flat() -> yield x
ij
Combine the ops flat()
and map(f)
.
flat() -> yield f(x
ij)
Works as Array.prototype.forEach
.
Works as Array.prototype.join
.
Returns last iterator value.
last() -> return x
length - 1
Work as Array.prototype.map
.
Receives n iterators and returns an iterator. This one emit all values of each iterator and emits sequencially each value in the same position.
For example:
numbers -> 0, 1, 2, 3, 4, 5
chars -> a, b, c, d, e, f
merge(numbers, chars) -> 0, a, 1, b, 2, c, 3, d, 4, e, 5, f
merge(it
1, ..., it
n) -> yield x
in
Calls all high over functions / ops taking like parameter the result of before call. The first argument is the original iterator (this).
pipe(f
0, ..., f
n) -> f
n(f
0(this))
Works as Array.prototype.reduce
.
Works as Array.prototype.some
.
Takes a range of iterator values from 0 to n.
take(n) -> yield x
i < n
Iterate and takes a value in the same position from two iterators (original iterator and it) and calls a function with two arguments where first argument is original iterator value and second the other iterator's value.
If one of iterators close, it close other too.
For example:
numbers -> 0, 1, 2, 3, 4, 5
chars -> a, b, c, d, e, f
numbers.zip(chars, f) -> f(0, a), f(1, b), f(2, c), f(3, d), f(4, e), f(5, f)
zip(it, f) -> yield f(this
i, it
i)