https://github.com/slavahatnuke/apipe
Functional pipes and promise based pipes.
https://github.com/slavahatnuke/apipe
Last synced: 2 months ago
JSON representation
Functional pipes and promise based pipes.
- Host: GitHub
- URL: https://github.com/slavahatnuke/apipe
- Owner: slavahatnuke
- Created: 2017-03-18T13:57:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-19T18:19:46.000Z (about 8 years ago)
- Last Synced: 2025-03-08T12:43:25.401Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# apipe
Functional pipes and promise based pipes.```javascript
const assert = require('assert');
const {pipe, promisePipe} = require('..');describe('test', () => {
it('pipe', () => {let addOne = (it) => it + 1;
let addTwo = (it) => it + 2;let xpipe = pipe(addOne, addTwo);
assert.equal(xpipe('hello'), 'hello12');
assert.equal(xpipe(5), 8);
});it('pipe / array constructor', () => {
let addOne = (it) => it + 1;
let addTwo = (it) => it + 2;let xpipe = pipe([addOne, addTwo], addOne, [addTwo, addTwo]);
assert.equal(xpipe('hello'), 'hello12122');
assert.equal(xpipe(10), 18);
});it('promise pipe', () => {
let timeout = (time) => new Promise((resolve, reject) => setTimeout(resolve, time));
let addOne = (it) => Promise.resolve()
.then(() => timeout(1))
.then(() => it + 1);let addTwo = (it) => it + 2;
let xpipe = promisePipe(addOne, addTwo);
return xpipe('hello')
.then((result) => assert.equal(result, 'hello12'))
.then(() => xpipe(10))
.then((result) => assert.equal(result, 13))
.then(() => xpipe('done'))
.then((result) => assert.equal(result, 'done12'));
})it('promise pipe / with array constructor', () => {
let addOne = (it) => it + 1;
let addTwo = (it) => it + 2;let xpipe = promisePipe(addOne, addTwo, [addOne, addTwo, addTwo]);
return xpipe('hello')
.then((result) => assert.equal(result, 'hello12122'))
.then(() => xpipe(10))
.then((result) => assert.equal(result, 18))
})
});
```