Lazy Evaluation in JavaScript
Deferring work until a value is actually needed, with iterators, generators and iterator helpers, and when it saves time and memory compared with arrays.
Content tagged lazy-evaluation
Snippet:First N Matches from Any Iterable with
filter()andtake()Get the first N matches and stop reading.Return the first N matches from any iterable with Iterator.from(), filter() and take(), stopping as soon as it has enough, even on infinite sequences.Tutorial:Iterator Helpers: Lazy Pipelines over Any Iterator
Map, filter and take over any iterator, lazily.Use ES2025 iterator helpers (map, filter, take, drop, flatMap, reduce, Iterator.from) to build lazy pipelines over generators, Sets, Maps and infinite sequences.