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.
29 lines
755 B
JavaScript
29 lines
755 B
JavaScript
4 years ago
|
"use strict";
|
||
|
|
||
|
const Promise = require("bluebird");
|
||
|
const propagateAbort = require("@ppstreams/propagate-abort");
|
||
|
const propagatePeek = require("@ppstreams/propagate-peek");
|
||
|
|
||
|
const { validateArguments } = require("@validatem/core");
|
||
|
const required = require("@validatem/required");
|
||
|
const isFunction = require("@validatem/is-function");
|
||
|
|
||
|
module.exports = function mapStream(_mapCallback) {
|
||
|
let [ mapCallback ] = validateArguments(arguments, {
|
||
|
mapCallback: [ required, isFunction ]
|
||
|
});
|
||
|
|
||
|
return {
|
||
|
description: `map stream`,
|
||
|
abort: propagateAbort,
|
||
|
peek: propagatePeek,
|
||
|
read: function produceValue_mapStream(source) {
|
||
|
return Promise.try(() => {
|
||
|
return source.read();
|
||
|
}).then((value) => {
|
||
|
return mapCallback(value);
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
};
|