Skip to content

Instantly share code, notes, and snippets.

@hsharghi
Created December 13, 2019 01:01
Show Gist options
  • Save hsharghi/516344105ce070dccb56966605557c58 to your computer and use it in GitHub Desktop.
Save hsharghi/516344105ce070dccb56966605557c58 to your computer and use it in GitHub Desktop.
virgool-blog-0002
struct PostAndComments {
var post: Post
var comments: [Comment]
}
func showPostsWithComments() -> Future<[PostAndComments]> {
return getPostsFromDatabase().flatMap { posts -> Future<[PostAndComments]> in
return posts.flatMap { post -> Future<[PostAndComments]> in
return post.getComments().map { comments -> [PostAndComments] in
return PostAndComment(post: post, comments: comments)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment