There's more...

We can also modify our map building operation to a more concise form by using the mapValues function:

fun getCoursesWithSubscribedStudents(): Map<Course, List<Student>> =
getStudents()
.flatMap { student ->
student.courses.map { course -> course to student }
}
.groupBy { (course, _) -> course }
.mapValues { (course, courseStudentPairs) ->
courseStudentPairs.map { it -> it.second }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.164.210