Browse Source

Initial commit

master
Sven Slootweg 2 months ago
commit
9d1014c49d
  1. 3
      .eslintrc
  2. 1
      .gitignore
  3. 43
      index.js
  4. 24
      package.json
  5. 1140
      yarn.lock

3
.eslintrc

@ -0,0 +1,3 @@
{
"extends": "@joepie91/eslint-config"
}

1
.gitignore

@ -0,0 +1 @@
node_modules

43
index.js

@ -0,0 +1,43 @@
"use strict";
const Promise = require("bluebird");
const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const isFunction = require("@validatem/is-function");
const propagateAbort = require("@promistream/propagate-abort");
const propagatePeek = require("@promistream/propagate-peek");
module.exports = function mapFilter(_predicate) {
let [ predicate ] = validateArguments(arguments, {
predicate: [ required, isFunction ]
});
return {
_promistreamVersion: 0,
description: `map-filter stream`,
abort: propagateAbort,
peek: propagatePeek,
read: function produceValue_mapFilterStream(source) {
function attemptRead() {
return Promise.try(() => {
return source.read();
}).then((result) => {
return Promise.try(() => {
return predicate(result);
}).then((mappedItem) => {
if (mappedItem === module.exports.NoValue) {
return attemptRead();
} else {
return mappedItem;
}
});
});
}
return attemptRead();
}
};
};
module.exports.NoValue = Symbol("NoValue");

24
package.json

@ -0,0 +1,24 @@
{
"name": "@promistream/map-filter",
"description": "A Promistream that's optimized for the 'map some items and throw away the rest' usecase",
"version": "0.1.0",
"main": "index.js",
"keywords": [
"promistream"
],
"repository": "http://git.cryto.net/joepie91/map-filter.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"devDependencies": {
"@joepie91/eslint-config": "^1.1.0",
"eslint": "^6.8.0"
},
"dependencies": {
"@promistream/propagate-abort": "^0.1.6",
"@promistream/propagate-peek": "^0.1.1",
"@validatem/core": "^0.3.15",
"@validatem/is-function": "^0.1.0",
"@validatem/required": "^0.1.1",
"bluebird": "^3.7.2"
}
}

1140
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save