/gen-z

Helpers for generators.

Primary LanguageJavaScriptMIT LicenseMIT

Gen-z

UNMAINTAINED - Since I don't use it and it's still JS, not TS, I'm not going to maintain this any longer.

Next generation (lol) generator helpers.

Think any utility library (ramda, lodash) but for generators.

npm install @yeldirium/gen-z
# or
yarn install @yeldirium/gen-z

Status

Category Status
Version npm
Dependencies David
Dev dependencies David
Build GitHub Actions
License GitHub

Short guide

Everything with more than one parameter is curried.

Process and acknowledge events from somewhere:

const g = require('gen-z').sync;
const generator = fetchEventsAsGenerator(fromSomewhere);

const acknowledgable = g.acknowledgable(generator, acknowledgeEventCallback);

g.forEach(
  event => {
    try {
      processEventSomehow(event);
    
      // Acknowledge the event.
      return true;
    } catch {
      // Or make the generator re-yield the event.
      return false;
    }
  },
  acknowledgable
);

Get the powers of 2 from 2^10 to 2^15:

const g = require('gen-z').sync;

console.log(
    g.collect(
        g.take(
            5,
            g.drop(
                10,
                g.iterate(a => a * 2, 1)
            )
        )
    )
);

Documentation

Here.