Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
val films = directors.flatMap(director => director.films)
def averageScore:Int = films.foldLeft(0)((a, b) => a.imdbRating + b.imdbRating) / films.length
Error:(60, 58) value imdbRating is not a member of Int
def averageScore:Int = films.foldLeft(0)((a, b) => a.imdbRating + b.imdbRating) / films.length
sum
is equivalent to reduce(_ + _)
, or fold(0)(_ + _)
apply
is defined in Foo