generator-utility

utility functions to make everyday with generator easier

Usage no npm install needed!

<script type="module">
  import generatorUtility from 'https://cdn.skypack.dev/generator-utility';
</script>

README

build_status statements functions

This repo contains functions that makes it easy to program with AsyncGenerators in a functional programming friendly way.

API

  • flatten <T>(array: AsyncGenerator<T, any, unknown>[]) => AsyncGenerator<T, void, unknown>

  • generate <T, R>(fn: (el: T, index?: number, arr?: T[]) => Promise<R>) => (arr: T[]) => AsyncGenerator<R, void, unknown>

  • iterate

      interface IterateFn<T> {
          each?: EachFn<T>
          done?: DoneFn<T>
      }
      type EachFn<T> = (yielded?: T, index?: number) => Promise<any>
      type DoneFn<T> = (yieldedArray?: T[]) => Promise<any>
    

    <T>(generator: AsyncGenerator<T, any, unknown>) => (fn: IterateFn<T>) => Promise<void>

  • iterateSync eachFn and doneFn are synchronous function rather than returning a promise.