Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 2 KB

README.md

File metadata and controls

47 lines (36 loc) · 2 KB

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