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

Jiacheng Zheng #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Jiacheng Zheng #4

wants to merge 1 commit into from

Conversation

zhenglei21887
Copy link

No description provided.

@leonchen83
Copy link
Contributor

    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);
            });
        }
    }
    public Observable<String> delayAll(Observable<String> source, long time, TimeUnit unit) {
        return source.concatMap(e -> Observable.just(e).delay(time, unit));
    }
    public Observable<String> distinct(Observable<String> source) {
        return source.groupBy(e -> e).map(e -> e.getKey());
    }
    public Observable<String> repeat(Observable<String> source, int count) {
        return Observable.range(0, count).concatMap(e -> source);
    }
    public Observable<Integer> iterate(Observable<Node> observable) {
        return observable.flatMap(n -> {
            Observable<Integer> left = n.left == null ? Observable.empty() : iterate(Observable.just(n.left));
            Observable<Integer> right = n.right == null ? Observable.empty() : iterate(Observable.just(n.right));
            return Observable.merge(left, right, Observable.just(n.value));
        });
    }

@zhenglei21887 zhenglei21887 changed the title test-pr zhengjiacheng-pr Mar 26, 2018
@leonchen83 leonchen83 changed the title zhengjiacheng-pr 郑家城 Mar 26, 2018
@leonchen83 leonchen83 changed the title 郑家城 Jiacheng Zheng 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