Last active
May 2, 2018 22:08
-
-
Save retrospectacus/a38cf10b14a4589cb4ae90a96cd9ca6b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class Book(title: String, category: String, rating: Int) | |
val t = List( | |
Book("The dark", "Mystery", 90), | |
Book("What is", "Romance", 55), | |
Book("This is what", "Mystery", 80), | |
Book("FPIS", "Reference", 99), | |
Book("Darker", "Mystery", 80), | |
Book("It isn't", "Romance", 82) | |
) | |
def zer(x: List[Book]) = { | |
x.groupBy(_.category).head._2 | |
} | |
zer(t) | |
def retro(x: List[Book]) = { | |
// x.groupBy(_.category).values.map(_.sortBy(_.rating).head) | |
x.groupBy(_.category).values.map(_.maxBy(_.rating)) | |
} | |
retro(t) | |
.foreach { | |
case Book(t, c, _) => | |
println(s"Top book for $c is $t") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment