3 ms·
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
by nicholastmosher 5y ago
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.
- nielsbot 5y agoI 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/2298686-reduce https://developer.apple.com/documentation/swift/array/229868...