f-pipe
v0.0.2-1
Published
A pipe system for Javascript
Downloads
4
Maintainers
Readme
F-PIPE
A pipe system for Javascript
Motivation
Sometimes in Javascript, you will do something like this:
let stateTree = { branch1: "apple", branch2: "pine", branch3: "coconut" }
stateTree = addMoreLight(stateTree);
stateTree = water(stateTree);
stateTree = treeShaking(stateTree);
stateTree = swing(stateTree);
stateTree = /*...*/
But what if:
const stateTree = { branch1: "apple", branch2: "pine", branch3: "coconut" }
Maybe you just want to:
cutDownTheTree(stateTree);
Solution:
const { select } = require('f-pipe');
const youngTree = { branch1: "apple", branch2: "pine", branch3: "coconut" }
const bigTree = select(youngTree)
.then(tree => singASong(tree))
.then(tree => lala(tree))
.then(/* i will do everything until it becomes a big tree */)
.get();
Install
npm install --save f-pipe
API Reference
.then
const youngTree = { branch1: "apple", branch2: "pine", branch3: "coconut" }
const bigTree = select(youngTree)
.then(tree => singASong(tree))
.then(tree => lala(tree))
.then(/* i will do everything until it becomes a big tree */)
.get();
.apply
const result = select(1).apply(sum, [2, 3, 4]).get();
console.log(result);
// => 10
.applyM
const cat = "a cat"
const describe = select(cat)
.applyM(String.prototype.concat, [
" is sitting on the window"])
.get();
console.log(describe);
// => a cat is siting on the window
.call
const a = 5;
const b = select(a).call(add, 2)
.call(multipy, 4)
.get();
console.log(b);
// => 14
.callM
const clock = new Clock();
const alarm = select(clock)
.callM(Clock.prototype.alarm, "8:30", "You're late for school!")
.get();
console.log(alarm);
// => '8:30 AM : You are late for school!'
.bulk
const youngTree = { branch1: "apple", branch2: "pine", branch3: "coconut" }
const bigTree = select(youngTree)
.bulk([
addMoreLight,
water,
fertilize,
/*...*/
]);
Changelog
Visit Github Release page for more information.