phobos/changelog/add_lazycache_function.dd
Aditya Chincholkar 1de571c710
Adding a lazy version of std.algorithm.iteration.cache #10687 Open Feature (#10709)
* added Lazycache feature

* Added Lazycache funtion

* changes as per review

* Update std/algorithm/iteration.d

Co-authored-by: Richard (Rikki) Andrew Cattermole <pbdadmin@gmail.com>

* removing unrelated change

* added lazychache in cheatsheet

* removed error

* add_lazycache_function.dd

* changes in changelog

* lines changes in changelog

* removing whitspace

---------

Co-authored-by: Richard (Rikki) Andrew Cattermole <pbdadmin@gmail.com>
2025-03-28 15:23:30 -07:00

15 lines
No EOL
560 B
Text

Add lazyCache to std.algorithm.iteration
The new `lazyCache` function provides a lazily evaluated range caching mechanism.
Unlike `cache`, which eagerly evaluates range elements during construction,
`lazyCache` defers evaluation until elements are explicitly requested.
---
auto result = iota(-4, 5).map!(a => tuple(a, expensiveComputation(a)))().lazyCache();
// No computations performed at this point
auto firstElement = result.front;
// First element is now evaluated
---
See the $(REF lazyCache, std,algorithm,iteration) documentation for more details.