digitalmars.D.learn - what's meaning of "(a) =>"
- step8 (13/13) Feb 05 2022 I'm trying to study D programming
- Stanislav Blinov (8/21) Feb 05 2022 `(a) => value.length==0 || a[field]==value`
- step8 (3/25) Feb 06 2022 Thanks very much.I think i kind of get that now.
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
Feb 05 2022
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
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`).
Feb 05 2022
On Saturday, 5 February 2022 at 15:17:05 UTC, Stanislav Blinov wrote:On Saturday, 5 February 2022 at 15:10:19 UTC, step8 wrote:Thanks very much.I think i kind of get that now.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 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`).
Feb 06 2022








step8 <step7 163.com>