Initial commit

master
Sven Slootweg 3 years ago
commit 66b859ddfe

@ -0,0 +1,3 @@
module.exports = {
extends: "@joepie91/eslint-config"
};

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

@ -0,0 +1,18 @@
"use strict";
const Promise = require("bluebird");
const pipe = require("@promistream/pipe");
const fromIterable = require("./");
const map = require("@promistream/map");
const collect = require("@promistream/collect");
Promise.try(() => {
return pipe([
fromIterable([ 1, 2, 3, 4 ]),
map((number) => number * 2),
collect()
]).read();
}).then((result) => {
console.log(result); // [ 2, 4, 6, 8 ]
});

@ -0,0 +1,31 @@
"use strict";
const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const ValidationError = require("@validatem/error");
const EndOfStream = require("@promistream/end-of-stream");
const simpleSource = require("@promistream/simple-source");
module.exports = function createStreamFromIterable(iterable) {
validateArguments(arguments, [
[ "iterable", required, (iterable) => {
// FIXME: Move to @validatem/ package
if (!(typeof iterable[Symbol.iterator] === "function")) {
throw new ValidationError("Must be an iterable (eg. an array)");
}
} ]
]);
let iterator = iterable[Symbol.iterator]();
return simpleSource(() => {
let { done, value } = iterator.next();
if (done) {
throw new EndOfStream("End of iterable reached");
} else {
return value;
}
});
};

@ -0,0 +1,23 @@
{
"name": "@promistream/from-iterable",
"version": "0.1.0",
"main": "index.js",
"repository": "http://git.cryto.net/promistream/from-iterable.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"devDependencies": {
"@joepie91/eslint-config": "^1.1.0",
"@promistream/collect": "^0.1.1",
"@promistream/map": "^0.1.1",
"@promistream/pipe": "^0.1.5",
"bluebird": "^3.7.2",
"eslint": "^6.3.0"
},
"dependencies": {
"@promistream/end-of-stream": "^0.1.1",
"@promistream/simple-source": "^0.1.2",
"@validatem/core": "^0.3.13",
"@validatem/error": "^1.1.0",
"@validatem/required": "^0.1.1"
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save