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

RES
let asIterable: t<'yield, 'return, 'next> => Iterable.t<'yield>

asIterable(iteratorObject) views iteratorObject as an Iterable.t.

asIterator

RES
let asIterator: t< 'yield, 'return, 'next, > => Iterator.t<'yield, 'return, 'next>

asIterator(iteratorObject) views iteratorObject as a bare Iterator.t.

drop

RES
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

RES
let every: (t<'yield, 'return, 'next>, 'yield => bool) => bool

every(iteratorObject, predicate) returns true if predicate is true for every yielded value.

filter

RES
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

RES
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

RES
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

RES
let forEach: (t<'yield, 'return, 'next>, 'yield => unit) => unit

forEach(iteratorObject, f) consumes iteratorObject and runs f for each yielded value.

ignore

RES
let ignore: t<'yield, 'return, 'next> => unit

ignore(iteratorObject) marks iteratorObject as intentionally unused.

map

RES
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

RES
let next: t< 'yield, 'return, 'next, > => Iterator.result<'yield, 'return>

next(iteratorObject) advances iteratorObject without sending a value back in.

nextValue

RES
let nextValue: ( t<'yield, 'return, 'next>, 'next, ) => Iterator.result<'yield, 'return>

nextValue(iteratorObject, value) advances iteratorObject, sending value back into it.

reduce

RES
let reduce: ( t<'yield, 'return, 'next>, ('acc, 'yield) => 'acc, ~initialValue: 'acc=?, ) => 'acc

reduce(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

RES
type result<'yield, 'return> = Iterator.result< 'yield, 'return, >

Result returned by IteratorObject.next.

some

RES
let some: (t<'yield, 'return, 'next>, 'yield => bool) => bool

some(iteratorObject, predicate) returns true if at least one yielded value satisfies predicate.

t

RES
type t<'yield, 'return, 'next> = Iterable.t<'yield>

Type representing an IteratorObject instance.

take

RES
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

RES
let toArray: t<'yield, 'return, 'next> => array<'yield>

toArray(iteratorObject) consumes iteratorObject and returns its yielded values as an array.

toArrayWithMapper

RES
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.