Skip to content

Instantly share code, notes, and snippets.

@zachgoll
Created September 12, 2020 02:31
Show Gist options
  • Save zachgoll/ab98bba4339de6c0949a2dca4d49524d to your computer and use it in GitHub Desktop.
Save zachgoll/ab98bba4339de6c0949a2dca4d49524d to your computer and use it in GitHub Desktop.
map operator
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