Streams

The easiest way to think of an event stream is not to think of the streams you've probably used before in programming, input reader streams, but to think of arrays. Let's say that you have an array with a series of numbers in it:

[1, 4, 6, 9, 34, 56, 77, 1, 2, 3, 6, 10]

Now you want to filter this array to only show you even numbers. In modern JavaScript this is easily done through the use of the filter function on the array:

[1, 4, 6, 9, 34, 56, 77, 1, 2, 3, 6, 10].filter((x)=>x%2==0) =>
[4, 6, 34, 56, 2, 6, 10]

A graphical representation can be seen here:

Streams

The filtering function here remains the same should we have ten items in the array or ...

Get JavaScript: Functional Programming for JavaScript Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.