Finding Max Value of Column in Multi-Dimesional Array
dwdv
dwdv at posteo.de
Fri Jul 5 20:20:58 UTC 2019
On 7/5/19 9:56 PM, ag0aep6g via Digitalmars-d-learn wrote:
> On 05.07.19 20:49, Samir wrote:
>> As a follow-on to my earlier question, is there a way to pass a
>> variable to the `map` function that specifies the column, rather than
>> hard-coding it? I'm thinking of something like:
>>
>> p.map!("a[column]").maxElement.writeln;
>
> You can't do that with the string style, because the string is turned
> into a function inside of `map`. Your `column` isn't visible there.
>
> It works when you pass an actual callable instead, e.g. a lambda:
>
> p.map!(a => a[column]).maxElement.writeln;
Furthermore, Samir, the parameter `a` can be renamed to whatever you
prefer or what fits the code at hand best, e.g. `(row => row[column])`,
as opposed to the string version, where only a small set of mostly
single character names is supported.
More information about the Digitalmars-d-learn
mailing list