Last active
May 21, 2018 16:12
-
-
Save joan38/7f0a92b77b9d1bb69eb8ce29a30c9052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postsByAuthor | |
| .join(usersByKey, | |
| (posts: Set[Post], author: User) => | |
| posts.map(DenormalisedPost(_, author, DenormalisedPost.Interactions(Set.empty, 0)))) | |
| .toStream | |
| .flatMapValues(identity) | |
| .groupBy((_, denormalisedPost) => denormalisedPost.post.id) | |
| .reduce((first, second) => if (first.post.updatedOn.isAfter(second.post.updatedOn)) first else second) | |
| .leftJoin(likesByKey, | |
| (denormalisedPost: DenormalisedPost, likes: Set[Like]) => | |
| Option(likes).fold(denormalisedPost)(denormalisedPost.lens(_.interactions.likes).set(_))) | |
| .leftJoin(commentCountByKey, | |
| (denormalisedPost: DenormalisedPost, commentCount: Int) => | |
| denormalisedPost.lens(_.interactions.comments).set(commentCount)) | |
| .toStream | |
| .to("denormalised-posts") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment