Skip to content

Instantly share code, notes, and snippets.

@miszmaniac
Created May 10, 2017 09:13
Show Gist options
  • Save miszmaniac/8f103dac860e4c0ab2f6e492985e64e4 to your computer and use it in GitHub Desktop.
Save miszmaniac/8f103dac860e4c0ab2f6e492985e64e4 to your computer and use it in GitHub Desktop.
O TAK
class User {
public int id;
public User(int id) {
this.id = id;
}
}
class Post {
public Post(Post post, User user) {
this.id = post.id;
this.userId = post.userId;
this.user = user;
}
public Post(int id, int userId) {
this.id = id;
this.userId = userId;
}
public int id;
public User user;
public int userId;
}
ArrayList<User> source = new ArrayList<>();
source.add(new User(1));
source.add(new User(2));
source.add(new User(3));
source.add(new User(4));
Observable<User> userObservable = Observable.fromIterable(source);
ArrayList<Post> source1 = new ArrayList<>();
source1.add(new Post(1, 1));
source1.add(new Post(2, 1));
source1.add(new Post(3, 2));
source1.add(new Post(4, 2));
List<Post> posts = Observable.fromIterable(source1)
.flatMap(post -> userObservable.flatMap(user -> post.userId == user.id ? Observable.just(new Post(post, user)) : Observable.never()))
.toList()
.blockingGet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment