UNPKG

rafa

Version:

Rafa.js is a Javascript framework for building concurrent applications.

32 lines (25 loc) 1.24 kB
// # constructor() // An Enumerator is an object that defines a `next(callback)` method, which // provides the callback with a single Message in a series of values. function Enumerator() {} inherit(Enumerator, Rafa, { CompleteError: new RangeError("Enumerator is complete") }); // Static API extend(Enumerator, { // # array(Array): ArrayEnumerator // Create an iterator that produces a Message for all but the last value // in the array parameter and a DoneMessage for the last value. Calls // after the last value will throw a RangeError. `(Array) => (=> Message)` array(array) { return new ArrayEnumerator(array); }, // # empty(): EmptyEnumerator // Create an iterator that produces an empty DoneMessage on the first call // and throws a RangeError on subsequent calls. `() => (=> Message)` empty() { return new EmptyEnumerator(); }, // # until(generator: () => A, stop: A): UntilEnumerator // Create an iterator that produces a Message by calling a function // `generator` that produces values. DoneMessage is produces when the value // returned from `generator` equals `stop`. The default for `stop` is // undefined. until(generator, stop) { return new UntilEnumerator(generator, stop); } });