Created
September 12, 2020 02:31
-
-
Save zachgoll/ab98bba4339de6c0949a2dca4d49524d to your computer and use it in GitHub Desktop.
map operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { interval } = Rx; | |
const { map, take } = RxOperators; | |
// The input observable will emit the values 1, 2, 3 | |
// in 1 second intervals | |
function inputObservable() { | |
const returnValues = [1, 2, 3]; | |
return interval(1000) | |
.pipe( | |
take(returnValues.length), | |
map(val => returnValues[val]) | |
); | |
} | |
// ===================================== | |
// Don't worry about anything above this | |
// | |
// Just know that the input Observable | |
// returns the values 1, 2, 3 | |
// ===================================== | |
inputObservable().pipe( | |
// 10 * 1 = 10 | |
// 10 * 2 = 20 | |
// 10 * 3 = 30 | |
map(x => 10 * x) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment