Re: map! evaluates twice

2022-06-16 Thread Ali Çehreli via Digitalmars-d-learn
On 6/16/22 00:58, Salih Dincer wrote: > I guess the developed cached() and cache() are different things, > right? cache caches only the front element. https://dlang.org/library/std/algorithm/iteration/cache.html > I tried cached() cached() is supposed to cache as many elements as needed as

Re: map! evaluates twice

2022-06-16 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 10 June 2022 at 22:10:10 UTC, Ali Çehreli wrote: [...] I am trying to finish a .cached range algorithm that caches all elements that are in use. (It must drop old elements so that an infinite range does not require infinite cache.) It is supposed to evaluate elements only once. I

Re: map! evaluates twice

2022-06-12 Thread Antonio via Digitalmars-d-learn
On Friday, 10 June 2022 at 20:47:14 UTC, Steven Schveighoffer wrote: On 6/10/22 4:33 PM, Antonio wrote: ... `map` calls the lambda for each call to `front`. If you want a cached version, use `cache`: Thank you very much, Steve

Re: map! evaluates twice

2022-06-10 Thread Ali Çehreli via Digitalmars-d-learn
On 6/10/22 13:47, Steven Schveighoffer wrote: > `map` calls the lambda for each call to `front`. If you want a cached > version, use `cache`: Others don't know but as I will likely show during a lightning talk at DConf, I am trying to finish a .cached range algorithm that caches all elements t

Re: map! evaluates twice

2022-06-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/10/22 4:33 PM, Antonio wrote: When mapping and filtering, the last mapped element is evaluated twice... Is it the expected behaviour? ```d void main() {     import std.algorithm, std.stdio;     [1,2,3,4,5].     map!((x){     writeln("mapping ", x);     return x;

map! evaluates twice

2022-06-10 Thread Antonio via Digitalmars-d-learn
When mapping and filtering, the last mapped element is evaluated twice... Is it the expected behaviour? ```d void main() { import std.algorithm, std.stdio; [1,2,3,4,5]. map!((x){ writeln("mapping ", x); return x; }).