transversal sum
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 6 09:19:18 PST 2014
On Thursday, 6 November 2014 at 16:57:50 UTC, Marc Schütz wrote:
> On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame
> wrote:
>> I have rectangular forward range of forward ranges (not
>> arrays):
>> [
>> [a11, a12, ... a1N],
>> [a21, a22, ... a2N],
>> ...
>> [aM1, aM2, ... aMN]
>> ]
>>
>> I need lazy forward range:
>> [
>> a11 + a21 + ... aM1,
>> a12 + a22 + ... aM2,
>> ...
>> a1N + a2N + ... aMN
>> ]
>> Range of sum elements of every columns;
>>
>> M, N - runtime values;
>>
>> Is there a way to do this using only Phobos algorithms and
>> range functions?
>
> Untested:
>
> import std.algorithm: map, sum;
> auto rangeOfSums = rectangularRange.map!(r => r.sum);
Sorry, I see you want columns...
I thought about std.range.frontTransversal, but it only returns a
range of values, not a range of ranges. That's... unhelpful :-(
More information about the Digitalmars-d-learn
mailing list