std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value in place, then you can call each on it. The first thing

Re: std.algorithm each documentation terse

2015-07-20 Thread John Colvin via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: Is there a way to write a void lambda that would work with each? Ugh, I hate that I can't edit posts. I meant to delete this line.

Re: std.algorithm each documentation terse

2015-07-20 Thread via Digitalmars-d-learn
On Monday, 20 July 2015 at 15:08:16 UTC, Nicholas Wilson wrote: But the lambda takes a ref parameter... Yes, but it never writes to it: x.each!((ref a) = a + 1); Instead, this should work: x.each!((ref a) = a = a + 1); ... as a short-hand for: x.each!((ref a) { a = a + 1; });

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 15:12:28 UTC, Marc Schütz wrote: On Monday, 20 July 2015 at 15:08:16 UTC, Nicholas Wilson wrote: But the lambda takes a ref parameter... Yes, but it never writes to it: x.each!((ref a) = a + 1); Instead, this should work: x.each!((ref a) = a = a + 1);

Re: std.algorithm each documentation terse

2015-07-20 Thread Meta via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value

Re: std.algorithm each documentation terse

2015-07-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:59:21 UTC, John Colvin wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: [...] Everything is exactly as I would expect. Lambdas with = are just shorthand that skips the return expression and std.algorithm.each just calls the lambda for each element

Re: std.algorithm each documentation terse

2015-07-20 Thread Jack Applegame via Digitalmars-d-learn
Also, map is lazy, but each isn't.

Re: std.algorithm each documentation terse

2015-07-20 Thread sigod via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. Why are you trying to use `each` in place which belongs to `map`?

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 21:24:37 UTC, sigod wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. Why are you