Setting a list of values
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 30 22:42:00 PDT 2016
On 04/30/2016 10:05 PM, Joel wrote:
> This has no effect:
> _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0); });
This is a common issue especially for people who know lambdas from other
languages. :)
Your lambda does not do any work. Rather, your lambda returns another
lambda, which is promptly ignored:
import std.stdio;
import std.algorithm;
void main() {
auto arr = [ 1, 2 ];
arr.each!(a => { writeln(a); }); // returns lambda for each a
}
The lambda that 'each' takes above is "given a, produce this lambda". .
To do the intended work, you need to remove the curly braces (and the
semicolon):
arr.each!(a => writeln(a));
Or, you could insert empty () to call the returned lambda but that would
completely be extra work in this case:
arr.each!(a => { writeln(a); }());
Ali
More information about the Digitalmars-d-learn
mailing list