Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. postsByAuthor
  2. .join(usersByKey,
  3. (posts: Set[Post], author: User) =>
  4. posts.map(DenormalisedPost(_, author, DenormalisedPost.Interactions(Set.empty, 0))))
  5. .toStream
  6. .flatMapValues(identity)
  7. .groupBy((_, denormalisedPost) => denormalisedPost.post.id)
  8. .reduce((first, second) => if (first.post.updatedOn.isAfter(second.post.updatedOn)) first else second)
  9. .leftJoin(likesByKey,
  10. (denormalisedPost: DenormalisedPost, likes: Set[Like]) =>
  11. Option(likes).fold(denormalisedPost)(denormalisedPost.lens(_.interactions.likes).set(_)))
  12. .leftJoin(commentCountByKey,
  13. (denormalisedPost: DenormalisedPost, commentCount: Int) =>
  14. denormalisedPost.lens(_.interactions.comments).set(commentCount))
  15. .toStream
  16. .to("denormalised-posts")
Add Comment
Please, Sign In to add comment