Open emil14 opened 1 month ago
If Add
would be a reducer itself then it would be a bit simpler
component AvgAge(acc int, cur User) (res int) {
nodes { Add<int> }
:acc -> add:acc
:el -> .age -> add:cur
add -> :res
}
Instead of something like
component AvgAge(acc int, cur User) (res int) {
nodes { add SomeAdapter{Add<int>} }
:acc -> add[0]
:el -> .age -> add[1]
add -> :res
}
The Problem
Turns out we've decided to have
Map
/Filter
/For
but forgot aboutReduce
. This comes from:Add
However, user needs to be able to implement custom reducing to solve tasks like "calculate average age of all people in a group".
This is even bigger problem for reduce operation because reduction is stateful, unlike
for/map/filter
reduce does need to maintain state between iterations (accumulator). That's the nature of reduce.Proposed Solution
Proposed by @Catya3 in #654 among with any other interesting ideas. The idea is to have generic
Reduce
higher-order component just like we haveMap
andFor
(and will haveFilter)
.Please ignore the fact that we
Add
like it has array-inport instead of accepting a stream, In reality we would need some kind of adapter/convertor. Also let's pretend that we just have a real stream in place of<stream_of_users>