Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xinyang Pan #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Xinyang Pan #5

wants to merge 2 commits into from

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