IteratorObject
A JavaScript iterator object that inherits from Iterator.prototype.
This models a helper-enabled iterator object that conforms to the iterator
protocol and also inherits from Iterator.prototype, providing the standard
iterator helper methods. This is stricter than IterableIterator.t, which only
models the structural protocol shape.
See Iterator on MDN.
asIterable
let asIterable: t<'yield, 'return, 'next> => Iterable.t<'yield>asIterable(iteratorObject) views iteratorObject as an Iterable.t.
asIterator
let asIterator: t<
'yield,
'return,
'next,
> => Iterator.t<'yield, 'return, 'next>asIterator(iteratorObject) views iteratorObject as a bare Iterator.t.
drop
let drop: (t<'yield, 'return, 'next>, int) => t<'yield, unit, unknown>drop(iteratorObject, count) returns a new iterator helper that skips the first count
yielded values.
every
let every: (t<'yield, 'return, 'next>, 'yield => bool) => boolevery(iteratorObject, predicate) returns true if predicate is true for every yielded value.
filter
let filter: (
t<'yield, 'return, 'next>,
'yield => bool,
) => t<'yield, unit, unknown>filter(iteratorObject, predicate) returns a new iterator helper containing only the
yielded values that satisfy predicate.
find
let find: (
t<'yield, 'return, 'next>,
'yield => bool,
) => option<'yield>find(iteratorObject, predicate) returns the first yielded value that satisfies
predicate, or None if nothing matches.
flatMap
let flatMap: (
t<'yield, 'return, 'next>,
'yield => Iterable.t<'mapped>,
) => t<'mapped, unit, unknown>flatMap(iteratorObject, f) maps each yielded value to another iterable and flattens the result.
forEach
let forEach: (t<'yield, 'return, 'next>, 'yield => unit) => unitforEach(iteratorObject, f) consumes iteratorObject and runs f for each yielded value.
ignore
let ignore: t<'yield, 'return, 'next> => unitignore(iteratorObject) marks iteratorObject as intentionally unused.
map
let map: (
t<'yield, 'return, 'next>,
'yield => 'mapped,
) => t<'mapped, unit, unknown>map(iteratorObject, f) returns a new iterator helper whose yielded values are
produced by applying f.
next
let next: t<
'yield,
'return,
'next,
> => Iterator.result<'yield, 'return>next(iteratorObject) advances iteratorObject without sending a value back in.
nextValue
let nextValue: (
t<'yield, 'return, 'next>,
'next,
) => Iterator.result<'yield, 'return>nextValue(iteratorObject, value) advances iteratorObject, sending value back into it.
reduce
let reduce: (
t<'yield, 'return, 'next>,
('acc, 'yield) => 'acc,
~initialValue: 'acc=?,
) => 'accreduce(iteratorObject, reducer, ~initialValue) combines all yielded values using
reducer.
If ~initialValue is omitted, the first yielded value becomes the initial accumulator,
so the accumulator type must match the yielded value type.
result
type result<'yield, 'return> = Iterator.result<
'yield,
'return,
>Result returned by IteratorObject.next.
some
let some: (t<'yield, 'return, 'next>, 'yield => bool) => boolsome(iteratorObject, predicate) returns true if at least one yielded value
satisfies predicate.
t
type t<'yield, 'return, 'next> = Iterable.t<'yield>Type representing an IteratorObject instance.
take
let take: (t<'yield, 'return, 'next>, int) => t<'yield, unit, unknown>take(iteratorObject, count) returns a new iterator helper that yields at most count
values.
toArray
let toArray: t<'yield, 'return, 'next> => array<'yield>toArray(iteratorObject) consumes iteratorObject and returns its yielded values as an array.
toArrayWithMapper
let toArrayWithMapper: (
t<'yield, 'return, 'next>,
'yield => 'mapped,
) => array<'mapped>toArrayWithMapper(iteratorObject, mapper) consumes iteratorObject, applies mapper
to each yielded value, and returns the mapped values as an array.