Simple pipelines in JS
Platform | Build Status |
---|---|
Linux | |
Windows |
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>
const pipel = require('pipel');
Loading the CommonJS module provides the pipel function.
Loading the JavaScript file for the pipel provides the pipel function
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
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
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