Reduce help..
Vladimir Panteleev
vladimir at thecybershadow.net
Fri Sep 2 10:24:25 PDT 2011
On Fri, 02 Sep 2011 20:11:38 +0300, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> string[2][] results;
> results ~= ["foo", ""];
> results ~= ["foobar", ""];
>
> size_t len;
> foreach (res; results)
> {
> len = max(len, res[0].length);
> }
>
> That gives me '6'. I want to convert this to functional-style code
> with reduce. I've tried:
>
> len = reduce!(max!"a[0].length")(results);
>
> That's not it. Any clues?
Here's another way which doesn't use map:
len = reduce!`max(a, b[0].length)`(0, results);
--
Best regards,
Vladimir mailto:vladimir at thecybershadow.net
More information about the Digitalmars-d-learn
mailing list