Episode 6 - Projection vs Filtering Monday, 23 Oct.
With the previous lessons, you have performed four different kinds of operations on streams. You have learned how to:
If you still don’t know about streams, immutability and reactivity, then you should start with Lesson 1.
There is a fifth important kind of operation yet to discover: filtering streams.
For this lesson, we need a new piece:
▬ isEven. It’s a function that accepts a
number as an argument, then:
- If it is an even number, it returns
- Otherwise, it returns
Please take this new card,
❚ filter, and the
❚ map card you received in Lesson 2. Both cards can use the
▬ isEven function as an argument.
We set the same function and the same input stream of numbers on those cards and compare the stream they return:
I’ll frequently re-use previous cards, in different context, with different arguments and in comparison with new ones. Through repetitions, reactive programming will eventually become second nature for you.
▬ isEven is used as:
- a project function on the
- a predicate function on the
A predicate returns
✔ true or
✘ false. This is how
❚ filter works with a predicate:
- Each event of the input stream is given to the predicate
- If the predicate returns
✔ true, the event can pass
- Otherwise, the event is ignored
- As a result, it returns a new stream of filtered values
So, you now know three reactive programming concepts and five kinds of stream operation! That’s something, you can celebrate. And still, there are more. More categories. More cards per category. More Monday lessons 😁.