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

Jiazheng Sun #7

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

Jiazheng Sun #7

wants to merge 3 commits into from

Conversation

Argun
Copy link

@Argun Argun commented Mar 26, 2018

@leonchen83 Practice2最简单的方法公布一下?

@leonchen83
Copy link
Contributor

    public Observable<Tuple2<String, Integer>> wordCount1(Observable<String> words) {
    	return words.groupBy(e -> e).flatMap(e -> e.count().toObservable().map(x -> Tuples.of(e.getKey(), x.intValue())));
    }

    public Single<Map<String, Integer>> wordCount2(Observable<String> words) {
        return words.reduce(new HashMap<String, Integer>(), (a, b) -> {
            if (a.containsKey(b)) { a.put(b, a.get(b) + 1); } else { a.put(b, 1); }
            return a;
        });
    }

@leonchen83 leonchen83 changed the title RxJava practice Jiazheng Sun 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