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 trying
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`?
Also, map is lazy, but each isn't.
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);
.
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 i
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; });
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
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 i
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.
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 I
10 matches
Mail list logo