How it works...

With the following flatMap operation, the getLecturesOfCoursesWithSubscribedStudents() function is transforms the collection of the Student type objects into the collection of the Course type by merging elements of the Student.courses: Collection<Course> property:

getStudents()
.flatMap { student: Student ->
student.courses
}

As the result, the preceding code returns the Collection<Course> type. The collection returned by the flatMap operation contains a set of all the courses all of the students (obtained from the getStudents() function) are subscribed to.

Next, in order to remove duplicated courses, we append the chain of operations with the distinct() function. Then, we use the map() function. It is responsible for transforming every single element of the Course type into its corresponding Lecturer type from the Course.lecturer property. Finally, we are applying the distinct() function once again to return the list of lecturers with no duplicates. 

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

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