Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active April 2, 2018 12:51
Show Gist options
  • Save deque-blog/cdbdbc202e31abd70186fa1b7d33c219 to your computer and use it in GitHub Desktop.
Save deque-blog/cdbdbc202e31abd70186fa1b7d33c219 to your computer and use it in GitHub Desktop.
public Iterable<PostSummary> suggestedPostsFor(ProfileId profileId) {
try {
Future<Iterable<ProfileId>> friendIds = friendsOf(profileId);
Set<Topic> topics = favoriteTopicsOf(profileId).get();
Stream<PostSummary> interestingPosts = stream(friendIds.get())
.parallel() // Stream parallelization
.flatMap(friendId -> lastPostsOf(friendId))
.filter(post -> post.isAbout(topics));
return mostLiked(3, interestingPosts);
} catch (Exception e) { // InterruptedException and ExecutionException
// Raise high level abstract error?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment