On Saturday, 5 February 2022 at 15:10:19 UTC, step8 wrote:
I'm trying to study D programming
Following is code from vibe's example(web_ajax) code:
~~~~
void getDataFiltered(Fields field, string value)
{
auto table = users.filter!((a) => value.length==0 || a[field]==value)().array();
        render!("createTable.dt", table)();
}
~~~~
I can't understand the expression "(a) =>",there is no defination of "a",how does this work?
thanks for help

`(a) => value.length==0 || a[field]==value`

is a https://dlang.org/spec/expression.html#FunctionLiteral (see e.g. #10 there).

This one is polymorphic, somewhat equivalent to defining a function such as

`bool func(T)(T a) { return value.length==0 || a[field]==value; }`

(assuming `value` is accessible to `func`).

Reply via email to