Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

lxsmnsyc/pipel

Repository files navigation

pipel

Simple pipelines in JS

NPM

HitCount

Platform Build Status
Linux Build Status
Windows Build status

Install

NPM

npm i pipel

CDN

  • jsDelivr
<script src="https://cdn.jsdelivr.net/npm/pipel/dist/index.min.js"></script>
  • unpkg
<script src="https://unpkg.com/pipel/dist/index.min.js"></script>

Usage

Loading the module

CommonJS

const pipel = require('pipel');

Loading the CommonJS module provides the pipel function.

Browser

Loading the JavaScript file for the pipel provides the pipel function

Piping

pipel provides a curried function which allows to build pipelines.

Calling pipel returns a function which uses the given value as the seed for the pipeline.

The returned function must be provided with functions which reduces in sequence, returning the reduced result.

const result = pipel(1)(
  x => `Next: ${x}`,
  x => x.length,
);

console.log(result); // 7

Example

const map = mapper => source => {
  const result = [];

  for (const i of source) {
    result.push(mapper(i));
  }

  return result;
};

const filter = predicate => source => {
  const result = [];

  for (const i of source) {
    if (predicate(i)) result.push(i);
  }

  return result;
};

const result = pipel([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])(
  filter(x => x % 2 === 0),
  map(x => x * 2),
  map(x => `Next: ${x}`),
);

for (const i of result) {
  console.log(i);
};

Output

Next: 4
Next: 8
Next: 12
Next: 16
Next: 20

Build

Clone the repo first, then run the following to install the dependencies

npm install

To build the coverages, run the test suite, the docs, and the distributable modules:

npm run build

Releases

No releases published

Sponsor this project

 

Packages

No packages published