Created
February 11, 2019 18:10
-
-
Save pjagielski/59f1ee15c9e9339306928e8ccb936182 to your computer and use it in GitHub Desktop.
This file contains 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
fun Iterable<ResultRow>.toArticles(): List<Article> { | |
return fold(mutableMapOf<ArticleId, Article>()) { map, resultRow -> | |
val article = resultRow.toArticle() | |
val tagId = resultRow.tryGet(ArticleTagTable.tagId) | |
val tag = tagId?.let { resultRow.toTag() } | |
val current = map.getOrDefault(article.id, article) | |
map[article.id] = current.copy(tags = current.tags + listOfNotNull(tag)) | |
map | |
}.values.toList() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment