Skip to content

Conversation

@XinYang-Pan
Copy link
Member

No description provided.

@leonchen83 leonchen83 changed the title Practices all done 潘新阳 Mar 26, 2018
@leonchen83
Copy link
Contributor

    public Observable<String> repeat(Observable<String> source, int count) {
        return Observable.range(0, count).concatMap(e -> source);
    }

    public Maybe<String> elementAt(Observable<String> source, int index) {
        return source.zipWith(Observable.range(0, Integer.MAX_VALUE), (a, b) -> Tuples.of(a, b)).filter(x -> x.getV2() == index).map(e -> e.getV1()).firstElement();
    }

    public Observable<String> concat(List<Observable<String>> source) {
        return Observable.create(emitter -> { concat(source, emitter); });
    }

    private void concat(List<Observable<String>> source, ObservableEmitter<String> emitter) {
        if (source.isEmpty()) {
            emitter.onComplete();
        } else {
            source.get(0).subscribe(e -> {
                emitter.onNext(e);
            }, e -> emitter.onError(e), () -> {
                concat(source.subList(1, source.size()), emitter);
            });
        }
    }

@leonchen83 leonchen83 changed the title 潘新阳 xinyang Pan Mar 26, 2018
@leonchen83 leonchen83 changed the title xinyang Pan Xinyang Pan Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants