I can use filter algorithm with my types easily.
struct A
{
string value;
int count;
}
void main( string[] args )
{
A[] aArr;
aArr ~= A(HTTP, 3);
aArr ~= A(HTTPS, 2);
aArr ~= A(UNKNOWN_TCP, 4);
aArr.filter!( a = a.count == 2);
But I
On 8/02/2015 1:47 a.m., Kadir Erdem Demir wrote:
I can use filter algorithm with my types easily.
struct A
{
string value;
int count;
}
void main( string[] args )
{
A[] aArr;
aArr ~= A(HTTP, 3);
aArr ~= A(HTTPS, 2);
aArr ~= A(UNKNOWN_TCP, 4);
On 2015-02-07 at 13:47, Kadir Erdem Demir wrote:
auto sum = aArr.reduce!((a,b) = a.count + b.count);
The line above gives
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(770): Error: cannot
implicitly convert expression (__lambda3(result, front(_param_1))) of type int
to A
auto sum = aArr.map!`a.count`.reduce!((a,b) = a + b);
Rikki Thanks a lot. It works.
Function map!a.count(aArr) surprises me a little.
Because when I read std.algorithm reference: `Implements the
homonym function (also known as transform)`.
Which reminds me C++ transform and it will never
On Saturday, 7 February 2015 at 13:38:00 UTC, Kadir Erdem Demir
wrote:
How can I imagine what map does in my mind, because it
doesn't matches with the transform concept in my mind?
You can think of map as taking a range of something (in this
case, an array of A), and calling a user-supplied