Skip to content

A Minimalistic, extensible and lazy sequence implementation for Typescript and Javascript.

License

Notifications You must be signed in to change notification settings

tinyield/tinyield4ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

35f29ee · Jul 19, 2022

History

86 Commits
Dec 8, 2020
Jan 5, 2021
Dec 24, 2019
Dec 8, 2020
Dec 8, 2020
Jun 24, 2020
Dec 8, 2020
Dec 8, 2020
Jun 25, 2020
Jun 25, 2020
Dec 8, 2020
Jul 19, 2022
Jan 5, 2021
Jan 5, 2021
Dec 8, 2020

Repository files navigation

Tinyield4ts

npm version Quality Gate Status Coverage Bugs Vulnerabilities

A Minimalistic, extensible and lazy sequence implementation for Typescript and Javascript.

Usage

An auxiliary collapse() method, which merges series of adjacent elements is written with Tinyield in the following way:

import {Query, Traverser} from 'tinyield4ts';

function collapse<T>(src: Query<T>): Traverser<T> {
    return yld => {
        let prev: T;
        src.forEach(item => {
            if (prev === undefined || prev !== item) {
                prev = item;
                yld(item);
            }
        });
    };
}

This method can be chained in a sequence like this:

const arrange = [7, 7, 8, 9, 9, 11, 11, 7];
const actual = [];
Query.of(arrange)
    .then(n => collapse(n))
    .filter(n => n % 2 !== 0)
    .forEach(actual.push);

Installation

$ npm i tinyield4ts

License

This project is licensed under Apache License, version 2.0