question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Observable.endWith?

See original GitHub issue

I’m using Observable.startWith but would also like to use a new method Observable.endWith say (I suppose concat is not available because of static method with same signature after erasure).

The driver for me is that my code (in java) is heaps uglier without it.

Suppose I have source1, source2 and I want to do some stuff to source1 and then append source2:

I have three options:

Use static concat:

Observable.concat(source1.take(20).buffer(2,1).filter(myFilter), source2);

Use startWith:

source2.startWith(source1.take(20).buffer(2,1).filter(myFilter));

or use a new endWith method:

source1.take(20).buffer(2,1).filter(myFilter).endWith(source2);

The last one is much clearer. Am I overlooking something or can we can add this method to the api?

Perhaps a method like ``append` is better because it might seem strange to see multiple concatenated endWiths:

source1.endWith(source2).endWith(source3);

or

source1.append(source2).append(source3);

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
benjchristensencommented, Jul 24, 2014

We now have concatWith as an instance method.

public final Observable<T> concatWith(Observable<? extends T> t1)

You can now write code like this:

    public static void main(String[] args) {
        Observable<Integer> source1 = Observable.from(1, 2, 3, 4, 5);
        Observable<Integer> source2 = Observable.range(100, 5);
        source1
                .take(20)
                .buffer(2, 1)
                .filter(l -> l.size() == 2)
                .map(l -> l.get(0) + l.get(1))
                .concatWith(source2)
                .forEach(System.out::println);
    }

This outputs:

3
5
7
9
100
101
102
103
104
0reactions
dkuteynikovcommented, Sep 7, 2022

Actually, it would be great to also have concatWithItem, because we already have both startWith and startWithItem, while concatWith doesn’t have a similar shortcut to omit writing Observable.just.

Read more comments on GitHub >

github_iconTop Results From Across the Web

endWith - Learn RxJS
signature: endWith(an: Values): Observable ... If you want to start with a value instead, check out startWith ! ... Example 1: Basic endWith...
Read more >
rxjs - Why isn't there a endWith operator in Rx? - Stack Overflow
I have come up with this solution, but is there anything better? This thing gets a bit hard to read for what it...
Read more >
endWith - RxJS
Returns an observable that will emit all values from the source, then synchronously emit the provided value(s) immediately after the source completes.
Read more >
RxJS Operators / Michael Pishchagin - Observable
defer(observableFactory: function(): SubscribableOrPromise): Observable ... endWith(an: Values): Observable. Array(6) ["begin", 1, 2, 3, "end", "✓"] ...
Read more >
Observable | RxJS API Document - ReactiveX
Creates an Observable by using the addHandler and removeHandler functions to add and remove the handlers, with an optional selector function to project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found