Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This feature ("Aggregations for Smart Streams") sounds like what I'd normally call "reduce":

"Aggregates let you define functions that combine each record in a stream with some long-running state, or 'accumulator'."



Yes, this is very similar to "reduce" from the functional programming world, in fact it is equivalent to the "fold" pattern. The main difference is that fold is slightly more flexible since your accumulator may have a different type than your stream elements.

In Rusty pseudocode, reduce requires a function with two inputs and an output of the same type:

fn reduce<T>(f: Fn(T, T) -> T)

Whereas fold may use one type for the accumulator and another type for the elements, but requires an initial accumulator value to be given explicitly:

fn fold<A, T>(init: A, f: Fn(A, T) -> A)

The Aggregate SmartStreams discussed in the blog follow this fold pattern, applied to a distributed persistent log as the stream and using WebAssembly modules as the functions.


I didn't know about "fold"... In Swift it's still call `reduce` even if your accumulator type is arbitrary:

https://developer.apple.com/documentation/swift/array/229868...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: