In this lecture, we will look at one of the most popular operators from our SJS called the Map Operator.
This operator will handle transforming a value pushed from an observable.
We have complete control over the transformation of the value.
It's very similar to the map function for an array.
The main difference is that it'll work with observables instead of arrays.
Let's see it in action in our scripts.
We are going to replace the current observable with the of operator.
We will use the same example from before we will pass in five numbers.
Before outputting these numbers, we may want to transform them by adding a dollar sign symbol instead
of modifying the observable directly.
Let's modify it with a pipe operator.
The other function returns and observable.
Every observable object has a method called pipe.
It's common practice to change this method on the observable.
Inside this function, we can compose operators.
First, we need to import them at the top of the file.
We are going to make a new import statement from the SJS operators package.
Palpable operators can be found in a different location.
Operators that can be composed can be found under the SJS operators package, that's important to note.
Are SGX has organized these pipe cable operators under a different package?
Let's import the map operator.
Next, let's call it inside the pipe function.
We can configure the map operator by passing an arrow function, which accepts the value pushed from
the observable.
Keep in mind, the of operator will push a new value one at a time, each time a value is pushed, it'll
go through the pipe function.
The map operator will be given each value.
The value argument represents a single value.
It doesn't represent every value all at once.
We must return the modified value from this function.
Let's return the value argument with the dollar sign symbol.
In the console, the log will show the numbers prefixed with the symbol the observer is not receiving
the values directly from the original observable.
Instead, it subscribes to the observable returned by the map function.
As mentioned before, the original observable remains unaffected.
If we want, we can subscribe to the original observer and keep our new observable by breaking our pipe
into a different variable.
Let me show you what I mean.
Before chaining the pipe function, let's assume the pipe to a variable called numbers with symbol.
Just like that, we have to observables, we can subscribe to the original observable or the observable
that spits out the numbers with symbols in this console.
We will find the original observable values being logged.
It's because the subscription is being applied to the original observable.
Our SGX is very flexible.
We can create a single observable but emit different values by chaining different pipe functions.
There is an unlimited number of observables we can compose from a single observable before ending this
lecture.
I'm going to remove the numbers with symbols observable.
We will continue learning about operators in the next lecture.