Skip to content

Instantly share code, notes, and snippets.

@joepie91

joepie91/.js Secret

Last active June 13, 2020 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/78d8981fed2b22a5f31fb1fe468bd4b3 to your computer and use it in GitHub Desktop.
Save joepie91/78d8981fed2b22a5f31fb1fe468bd4b3 to your computer and use it in GitHub Desktop.
ppstreams example
"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