-
-
Save joepie91/78d8981fed2b22a5f31fb1fe468bd4b3 to your computer and use it in GitHub Desktop.
ppstreams example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const Promise = require("bluebird"); | |
const pipe = require("@ppstreams/pipe"); | |
const rangeNumbers = require("@ppstreams/range-numbers"); | |
const map = require("@ppstreams/map"); | |
const buffer = require("@ppstreams/buffer"); | |
const collect = require("@ppstreams/collect"); | |
function duplicateEven() { | |
return pipe( | |
map((value) => { | |
if (value % 2 === 0) { | |
return [value, value]; | |
} else { | |
return []; | |
} | |
}), | |
buffer() | |
); | |
} | |
return Promise.try(() => { | |
return pipe( | |
rangeNumbers(0, 20), | |
duplicateEven(), | |
collect() | |
).read(); | |
}).then((result) => { | |
console.log(result); | |
// [ 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18 ] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment