1.0.2 • Published 7 months ago

create-sequence v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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:

Please refer to tests for examples of different kinds of supported producers.

Sequence

Returned sequence allows access to the sequence values in multiple ways:

  1. value property is exposed to allow static access to the first value of the sequence
    const sequence = createSequence(['a', 'b', 'c']);
    console.log(sequence.value); // a 
  2. Sequence itself implements iterable protocol
    const sequence = createSequence(['a', 'b', 'c']);
    for (let v of sequence) {
        console.log(v); // prints a, b and c  
    }
  3. 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