expr icon indicating copy to clipboard operation
expr copied to clipboard

filter, map, but no reduce, no group

Open alexec opened this issue 4 years ago • 11 comments

It would be good to complete this set of operations.

I think group would be:

group(Prices,  {# > 10})

But I'm not sure the closure syntax can support reduce op due to the need for the closure to take two args, something like

reduce(Prices, 0, {.value + .acc})

alexec avatar Feb 14 '21 00:02 alexec

Yes, I’m also thinking about reduce built in for some time. Two arguments maybe done with for example #1, #2 or #acc named parameters.

But what should group func do?

antonmedv avatar Feb 14 '21 09:02 antonmedv

Group should partition an array into other arrays based on a key. Like SQL group by

alexec avatar Feb 14 '21 16:02 alexec

So it should return a map?

antonmedv avatar Feb 14 '21 19:02 antonmedv

I'm not sure. It could be an array of arrays, but the downside would be that you don't then know what the grouping key was.

I think the ultimate litmus test would be - can you do Hadoop style map-reduce?

https://techmytalk.com/2014/11/07/hadoop-mapreduce-group-by-operation-part1/#:~:text=The%20grouping%20of%20map%20output,the%20Map%20to%20the%20Reducer.

alexec avatar Feb 14 '21 20:02 alexec

@antonmedv I'm not sure I'm skilled enough to write these on my own, could we get one a Zoom and you show me how please?

alexec avatar Feb 18 '21 16:02 alexec

+1 for reduce, perhaps more than one param could be done by extending closures with a js-like "header" (x,y,z) => {...}, where the header is optional, and when not present basically becomes (#) => ?

mhr3 avatar Mar 12 '21 19:03 mhr3

Yes, also was thinking about (params) => {...} style. But what about {x, y => ...}?

antonmedv avatar Mar 12 '21 21:03 antonmedv

Looks like a closure returning two values: x and a bool :)

mhr3 avatar Mar 12 '21 21:03 mhr3

{#1 >= #2}

antonmedv avatar Mar 13 '21 00:03 antonmedv

@antonmedv Hi, any update on the reduce function?

pritamdey12 avatar Mar 10 '22 16:03 pritamdey12

Nope.

antonmedv avatar Mar 10 '22 17:03 antonmedv

So it should return a map?

yes, this feature is useful like as slice to map。

forrestlinfeng avatar Aug 23 '23 01:08 forrestlinfeng

Added groupBy func.

groupBy(1..9, # % 2)[1]

antonmedv avatar Aug 30 '23 09:08 antonmedv

Added reduce

reduce(1..9, # + #acc)
reduce(1..9, # + #acc, 0)

antonmedv avatar Aug 30 '23 11:08 antonmedv