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 linkedInProfiles: List[Profile] = … | |
// 1: Keep only profiles of young people | |
val youngProfiles: List[Profile] = linkedInProfiles.filter (p => p.age < 25) | |
// 2: Group these profiles by skill | |
val skillToProfile: List[(Skill, Profile)] = for { | |
p <- youngProfiles | |
s <- p.skills | |
} yield (s, p) | |
val profilesBySkill: Map[Skill, Profile] = | |
skillToProfile | |
.groupBy{ case (skill, profile) => skill) } | |
.mapValues{ case (skill, profiles) => profiles } | |
// 3: For each skill determine the number of profiles | |
val skillsWithPopularity: List[(Skill,Int)] = | |
profilesBySkill.mapValues( profiles => profiles.count ) | |
// 4: Order results by number of profiles and take top 10 skills | |
val top10Skills: List[(Skill, Int)] = | |
skillsWithPopularity | |
.sortBy{ case (skill, count) => - count} | |
.take(10) |
If you are confused by the Iteratees mentioned in previous post, take a look at this post.
No comments:
Post a Comment