Skip to content

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