@specialblend/fiterable

fluent/functional iterables: zero-dependency, fluent, composable iterators for Javascript with map, filter, concat

Usage no npm install needed!

<script type="module">
  import specialblendFiterable from 'https://cdn.skypack.dev/@specialblend/fiterable';
</script>

README

fiterable: fluent/functional iterables

fluent, composable iterators for Javascript with map, filter, concat

Key Features

  • ✓ Pure Javascript
  • ✓ Fluent interface
  • ✓ Includes functional-style exports

Installation

npm i @specialblend/fiterable

Quick Start

import * as R from 'ramda';
import { fiterable, Fiterable } from '@specialblend/fiterable';

const isEven = x => x % 2 === 0;

/**
 * Functional style
 * @type {Fiterable}
 */
const myFunctionalFit = fiterable(R.range(0, 10));
console.log(
    R.compose(
        R.map(R.multiply(3)),
        R.filter(isEven),
    )(myFunctionalFit),
);

/**
 * Fluent class style
 * @type {Fiterable}
 */
const myClassFit = new Fiterable(R.range(0, 10));
console.log(
    myClassFit
        .filter(isEven)
        .map(x => x * 3)
);

/**
 * Imperative for .. of style
 * @type {Fiterable}
 */
const myImperativeFit = new Fiterable(R.range(0, 10));
for (const x of myImperativeFit) {
    if (isEven(x)) {
        console.log(x * 3);
    }
}