create-sequence
v1.0.2
Published
Create sequence of values from given producer
Downloads
17
Readme
create-sequence
Simple module to allow creating unified interface for accessing sequence of values from different kinds of producers.
Usage
Usage is trivial, you only need to provide producer
function to obtain a sequence for it:
const sequence = createSequence(producer);
Producer
Producer can any of these types:
Array
Array
-like value- Object that implements iterable protocol
- Generator or Generator function
- Plain function that allows multiple calls and returns next sequence value for each call
Please refer to tests for examples of different kinds of supported producers.
Sequence
Returned sequence allows access to the sequence values in multiple ways:
value
property is exposed to allow static access to the first value of the sequenceconst sequence = createSequence(['a', 'b', 'c']); console.log(sequence.value); // a
- Sequence itself implements iterable protocol
const sequence = createSequence(['a', 'b', 'c']); for (let v of sequence) { console.log(v); // prints a, b and c }
- Sequence itself is a function that returns next sequence value on each subsequent call
const sequence = createSequence(['a', 'b', 'c']); console.log(sequence()); // a console.log(sequence()); // b console.log(sequence()); // c