Giter Club home page Giter Club logo

seqjs's Introduction

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

seqjs's People

Contributors

nyinyithann avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.