Initial commit

master
Sven Slootweg 3 years ago
commit 4359a24328

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

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

@ -0,0 +1,31 @@
"use strict";
const Promise = require("bluebird");
const fromLazyValue = require("./");
const pipe = require("@promistream/pipe");
const collect = require("@promistream/collect");
return Promise.try(() => {
console.log("Creating stream");
let lazyValueSource = fromLazyValue(() => {
console.log("Creating lazy value");
return 42;
});
console.log("Piping");
return pipe([
lazyValueSource,
collect()
]).read();
}).then((result) => {
console.log(result);
/*
Creating stream
Piping
Creating lazy value
[ 42 ]
*/
});

@ -0,0 +1,25 @@
"use strict";
const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const isFunction = require("@validatem/is-function");
const EndOfStream = require("@promistream/end-of-stream");
const simpleSource = require("@promistream/simple-source");
module.exports = function createStreamFromLazyValue(_valueGenerator) {
let [ valueGenerator ] = validateArguments(arguments, {
valueGenerator: [ required, isFunction ]
});
let wasValueRead = false;
return simpleSource(() => {
if (wasValueRead === false) {
wasValueRead = true;
return valueGenerator();
} else {
throw new EndOfStream("Value was read");
}
});
};

@ -0,0 +1,22 @@
{
"name": "@promistream/from-lazy-value",
"version": "0.1.0",
"main": "index.js",
"repository": "http://git.cryto.net/promistream/from-lazy-value.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/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/is-function": "^0.1.0",
"@validatem/required": "^0.1.1"
}
}

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