News for hackers. Stuff that matters.
Re:Aggregate streaming data in real-time with WebAssembly by nielsbot on Tuesday August 24, 2021 @02:33PM (#28292988)
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'."

Re:Aggregate streaming data in real-time with WebAssembly by nicholastmosher on Tuesday August 24, 2021 @03:09PM (#28293447)
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.

Re:Aggregate streaming data in real-time with WebAssembly by nielsbot on Tuesday August 24, 2021 @05:35PM (#28295294)
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...