Billy Newman
06/26/2023, 1:40 PMBilly Newman
06/26/2023, 1:43 PMopen class Person()
class Student(): Person()
class Teacher(): Person()
DB queries:
@Query("SELECT * from students WHERE important = 1")
fun observeStudents(): Flow<List<Person>>
@Query("SELECT * from teachers WHERE important = 1")
fun observeTeachers(): Flow<List<Person>>
Merge the flows:
fun observeImportantPeople(): Flow<List<Person>> {
val students = studentDao.observeStudents()
val teachers = teacherDao.observeTeachers()
return merge(students, teachers)
}
With 2 students and one teacher, I will see either 2 students in the flow list or 1 teacher in the flow list. Any ides?Sam
06/26/2023, 1:45 PMBilly Newman
06/26/2023, 1:51 PMType mismatch.
Required:
Iterable<Flow<TypeVariable(T)>>
Found:
Flow<List<Person>>
Sam
06/26/2023, 1:51 PMfun observeImportantPeople(): Flow<List<Person>> {
val students = studentDao.observeStudents()
val teachers = teacherDao.observeTeachers()
return combine(students, teachers) { s, t -> s + t }
}
Billy Newman
06/26/2023, 1:52 PMcombine(students, teachers)
Didn’t realize you have to provide a function specifying how to combine the lists
Thank you!