Created
April 5, 2022 04:18
-
-
Save katzkb/577f36d63d046331c75eb793b5a62546 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
// ①マップを生成 | |
val groupMap: Map[UserId, Seq[Group]] = | |
// ②マッピング数分回る | |
groupMemberSeq.groupBy(_.userId) map { case (userId, members) => | |
( | |
userId, | |
members.flatMap(member => // ③そのユーザーのマッピング数分回る | |
groupSeq.find(_.id == member.groupId) // ④Vectorのfindは実質定数 | |
) | |
) | |
} | |
val result: Seq[UserView] = userSeq.map(user => // ⑤ユーザー数分回る | |
UserView( | |
user.id, | |
user.name, | |
groupMap(user.id) // ⑥Map(HashMap)のfindなので実質定数 | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment