Well, this approach has the problem that the running sum of key k blocks
until a new value for that k arrives in the input stream.
If you wanted to know the sum of the values of each key after you got
nelements in the input stream, we could change the valuesWithKey
inner function into:
Hello
What do you think of this? There is perhaps a recursive call that should be
made tail recursive but it seems to work.
The 'group' function takes the list of pairs as input and outputs a list of
maps from key to sums.
The nth element of the list of maps corresponds to the grouping applied
I'm also learning Haskell so the solution below might be (1) inefficient and
(2) incorrect, but hey, let's give it a try :-)
For simplicity, in the testing code, I assume an infinite list of key/value
pairs where they keys are of type Char between 'a' and 'z' and the values
are Integers (the code
Hi,
let say I got an unordered lazy list of key/value pairs like
[('a', 99), ('x', 42), ('a', 33) ... ]
and I need to sum up all the values with the same keys.
So far I wrote a naive implementation, using Data.Map, foldl and insertWith.
The result of this grouping operation, which is
On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt gue.schm...@web.dewrote:
Hi,
let say I got an unordered lazy list of key/value pairs like
[('a', 99), ('x', 42), ('a', 33) ... ]
and I need to sum up all the values with the same keys.
So far I wrote a naive implementation, using
On Tue, Mar 24, 2009 at 3:51 PM, Luke Palmer lrpal...@gmail.com wrote:
On Tue, Mar 24, 2009 at 3:15 PM, Gü?nther Schmidt gue.schm...@web.dewrote:
Hi,
let say I got an unordered lazy list of key/value pairs like
[('a', 99), ('x', 42), ('a', 33) ... ]
and I need to sum up all the values
Gü?nther Schmidt gue.schm...@web.de writes:
let say I got an unordered lazy list of key/value pairs like
[('a', 99), ('x', 42), ('a', 33) ... ]
and I need to sum up all the values with the same keys.
So far I wrote a naive implementation, using Data.Map, foldl and insertWith.