1
votes

I have an Observable that looks more or less like this:

-a--b-c---d--e----f--->

where a, b, c, d, e, f are emitted values.

I want to split this Observable into two Observables, in such way that the last emitted value is "alone".

-a--b-c---d--e-------->

------------------f--->

Now, I want to wait for first Observable to completely finish (even inner Observables), after that, execute second Observable.

I know, that I should probably use concat, but I'm actually struggling with splitting Observable into two

2
So you want one stream with all values except the last and another with only the last?bryan60
Exactly, and then I want the first stream to finish before second startsfeerlay

2 Answers

3
votes

This seems fairly simple because there are skipLast and takeLast operators:

const source = ...;

const first = source.skipLast(1);
const second = source.takeLast(1);
1
votes
let Rx = require('rxjs/Rx');

let arr = ["a", "b", "c", "d", "e"]
let par = Rx.Observable.from(arr).partition((v, i) => i < arr.length - 1)
let res = Rx.Observable.concat(par[0], par[1])

res.subscribe(
    x => console.log('On Next: %s', x),
    e => console.log('On Error: %s', e),
    () => console.log('On Complete')
)