predicate factory : caching return value of boolean-returning-function and compose them
status: production ready
const specification = require("getto-specification");
const spec = specification.init();
const conditionA = spec.init(() => {
return heavy_condition_checker(); // return Promise
});
const text = "text";
const conditionB = spec.init(() => {
return (text === "text");
});
const compose = spec.all([
conditionA,
spec.not(conditionB),
]);
const result = await compose.matches();
console.log(result);
- Node.js : 10.16.0
const specification = require("getto-specification");
const spec = specification.init();
const conditionA = spec.init(() => {
return heavy_condition_checker(); // return Promise
});
const text = "text";
const conditionB = spec.init(() => {
return (text === "text");
});
const compose = spec.all([
conditionA,
spec.not(conditionB),
]);
const result = await compose.matches();
console.log(result);
const condition = spec.init(() => {
return BOOLEAN;
});
spec.init()
is caching function result
const condition = spec.not(another_condition);
return invert condition
const condition = spec.all([
conditionA,
conditionB,
]);
all conditions are sync-checking
matches: async () => {
for(let i in conditions) {
const condition = conditions[i];
if (!(await condition.matches())) {
return false;
}
}
return true;
}
npm install --save getto-specification
getto-specification is licensed under the MIT license.
Copyright © since 2019 shun@getto.systems