About filter() operator in Rxjs
It’s almost a year since my last publication. And yes, I have been quite busy.
Let’s get to the big deal.. Oh sorry, I will filter that... it’s not so big but it’s just a little tip to start off with my come back.
If you landed here then you know what Rxjs is and you also know about Observables.. so I will skip that!
If you are still asking questions.. jump in here… https://www.learnrxjs.io/
Observables return streams of data… Ok, that’s too much again, let’s filter that a little. Observables can change values within different times and gives you the power to see(observe) this change as they occur.
Notes taken? Now, let’s say you have an idea of what you are looking for and you really do not care about other changes that occur with this observable… You are probably thinking my thoughts… You filter that!
From the code above, our observable “source” changes from 1 up to 5. Now let’s say we don’t care about the odd numbers but we only want to see(observe) even numbers.
Using the filter() operator, we simply create a new observable from our “source” observable as seen in line 8. the function in the filter operator does the work and that is where you define what you want to observe.
So finally, when you observe your new “example” observable, you only get what you asked for; EVEN NUMBERS 2 and 4.
Got a better way to explain this? I will love to read.
