I'd like to map the value, but only the first time it's emitting. The other times it can pass through. Any ideas?
this.sourceStream$.takeUntil(this.onDestroy$).someFunc((data) => {
return data['some tranformation']
}).subscribe(data => {
If there any way to do this without a variable to track if the first value has been received?
Thanks!
The map operator has a second argument index that is automatically incremented:
this.sourceStream$.map((value, index) =>
index === 0 ? whatever(value) : value
);
What about using a combination of take skip and merge.
Something along these lines should do the trick, even if a bit verbose
const obs = Observable.interval(1000).take(4);
const obs1 = obs.take(1).map(val => 'I am the fist '+ val);
const obs2 = obs.skip(1);
merge(obs1, obs2).subscribe(console.log)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With