Skip to content
Snippets Groups Projects
Commit ef0ac4f9 authored by joel.vonderwe's avatar joel.vonderwe
Browse files

Collect exos improvments

parent aa4de7d7
No related branches found
No related tags found
No related merge requests found
*~
target/
.metals/
\ No newline at end of file
......@@ -37,17 +37,19 @@ object Collect {
/* Retourne la liste de morceaux associés à un artiste */
def tracksOf( artist: String ): List[Track] = {
albums.filter(_.artist == artist).flatMap( a => tracks(a.title))
albums.flatMap( a => if (a.artist == artist) tracks(a.title) else List())
}
/* Retourne la liste de tous les morceaux de moins de 4 minutes */
def shortTracks: List[Track] = {
tracks.flatMap(t => t._2).filter(t => t.duration.minutes < 4).toList
tracks.flatMap {
case (_,t) => t.filter(t => t.duration.minutes < 4)
}.toList
}
/* Retourne les titres des morceaux antérieurs à une année */
def titlesBefore( year: Int ): List[String] = {
albums.flatMap(a => if (a.year < year) tracks(a.title) else List()).map(_.title)
albums.flatMap(a => if (a.year < year) tracks(a.title).map(_.title) else List())
}
/* Calcule la durée totale de tous les morceaux disponibles.
......@@ -55,12 +57,9 @@ object Collect {
minutes peuvent dépasser ce total.
*/
def totalDuration: Duration = {
var m = 0
var s = 0
tracks.flatMap(_._2).foreach(t => {
m += t.duration.minutes
s += t.duration.seconds
})
Duration(m + s/60, s % 60)
val s = tracks.flatMap(_._2.map(t => {
t.duration.seconds + t.duration.minutes*60
})).sum
Duration(s/60, s % 60)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment