Skip to content

nyinyithann/SeqJS

Repository files navigation

This Project is only for educational purpose.

seq logo  SeqJS: Pipeline Operations for working with values of type Seq

SeqJS contains operations for working with values of type Seq which is a container of a series of elements. Types of a seq's elements are not fixed. Individual seq elements are computed only as required. Seq conforms iterable and iterator protocols of JavaScript.

GitHub CI Status

Node.js CI

Usage

A seq instance can be constructed as follows:

// An empty sequence
let seq = new Seq();
console.log([...seq]);
// => [];

// A sequence wrapped an array
let seq = new Seq([1, 2, 3]);
console.log([...seq]);
// => [1, 2, 3]

// A sequence wrapped a generator function
let seq = new Seq(function * () {
    yield 1;
    yield 2;
    yield 3;
});
console.log([...seq]);
// => [1, 2, 3]

// A sequence wrapped an iterator
const iterator = {
    i: 1,
    [Symbol.iterator] () {
        return this;
    },
    next () {
        if (this.i <= 3) {
            return { value: this.i++, done: false };
        }
        return { done: true };
    },
};
let seq = new Seq(iterator);
console.log([...seq]);
// => [1, 2, 3]

Seq is multi-iterable.

let seq = new Seq([1, 2, 3]);
for (const item of seq) {}
for (const item of seq) {}
console.log([...seq]);        
console.log([...seq]);  
// => [1, 2, 3]
// => [1, 2, 3]

Seq is closable.

let seq = new Seq([1, 2, 3, 4, 5]);
for (const item of seq) {
    if (item == 2) break;
}
console.log([...seq]);
// => [1, 2, 3, 4, 5]

API Document

Please read the API Docs for full details.

Author

Nyi Nyi Than - @nyinyithann

Credit

License

MIT

About

Pipeline Operations for working with values of type Seq.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published