You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
680 B
JavaScript

"use strict";
const Promise = require("bluebird");
const pipe = require("@promistream/pipe");
const rangeNumbers = require("@promistream/range-numbers");
const map = require("@promistream/map");
const collect = require("@promistream/collect");
const buffer = require("./");
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 ]
});