Fun Experiment: Bringing lazy execution to JS!
Harsh Joshi
Posted on January 17, 2022
Bringing lazy execution to higher order functions in JS!
How to Use
Install the package
npm i lazy-hofs
Add to your project
require("lazy-hofs");
lazySome()
let arr = [1, 2, 3, 4, 5, 6];
let ref = arr.lazySome((it) => {
return it === 9;
});
arr.push(9);
let result = ref.lazyEvaluate();
console.log(result);
lazyMap()
let arr = [1, 2, 3, 4, 5, 6];
let ref = arr.lazyMap((it) => {
return it * 9;
});
arr.push(9);
let result = ref.lazyEvaluate();
console.log(result);
lazyFilter()
let arr = [1, 2, 3, 4, 5, 6];
let ref = arr.lazyFilter((it) => {
return it % 2 === 0;
});
arr.push(9);
let result = ref.lazyEvaluate();
console.log(result);
lazyReduce()
let arr = [1, 2, 3, 4, 5, 6];
let ref = arr.lazyReduce((it, acc) => {
return (acc += it);
}, 0);
arr.push(9);
let result = ref.lazyEvaluate();
console.log(result);
Join me here: https://npmjs.com/package/lazy-hofs
Contributions welcome!
💖 💪 🙅 🚩
Harsh Joshi
Posted on January 17, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
privacy Caught in the Crunch My Journey from Snacks to 2 Million Exposed Users Privacy
November 30, 2024