Thread overview
what's meaning of "(a) =>"
Feb 05, 2022
step8
Feb 05, 2022
Stanislav Blinov
Feb 06, 2022
step8
February 05, 2022

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

February 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 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).

February 06, 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:

>

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).

Thanks very much.I think i kind of get that now.