UNPKG

rafa

Version:

Rafa.js is a Javascript framework for building concurrent applications.

27 lines (21 loc) 691 B
Group stream values into categories keyed by a string; fan-out. A handler function can be provided that translates values to strings, otherwise the message's value will be converted to a string and used as a key. <aside> ```js // group(...categories: String[, handler: Message => Message]): Stream var stream = Rafa.stream(); var groups = { small: [], big: [] }; var grouped = stream1.group("small", "big", v => { var group = "big"; if (v < 3) group = "small"; return group; }); grouped.small.each(v => groups.small.push(v)); grouped.big.each(v => groups.big.push(v)); stream.enumerate(Rafa.Enumerator.array([1,2,3,4]); // groups: // small: [1,2] // big: [3,4] ``` </aside>