ziv kesten
12/30/2020, 9:38 AMoverride suspend fun observeWatchedShows(): Flow<List<Show>> {
return watchListDao.observeShows()
//Map flow of list of Watched Shows to flow of list of Show
.map { listOfShows ->
entityMapper.toDomainList(
//Map list of WatchShows to list of ShowEntity
listOfShows.map { watchedShow -> watchedShow.show }
)
}
// Mapping Flow<List<WatchedShow>> -> Flow<List<ShowEntity>> -> Flow<List<Show>>
}
dave08
12/30/2020, 10:12 AMfun Flow<List<WatchedShow>>.mapToShowList()
out of it?ziv kesten
12/30/2020, 10:13 AMdave08
12/30/2020, 10:14 AMziv kesten
12/30/2020, 10:15 AMdave08
12/30/2020, 10:15 AMziv kesten
12/30/2020, 10:16 AMziv kesten
12/30/2020, 10:17 AMdave08
12/30/2020, 10:17 AMalbertosh
12/30/2020, 11:22 AMthe original function is in the repository which does not seem like a good place for extension functionAny place can be a good place for an extension function if makes sense. If it improves the readability, I see no major drawback in adding a private extension function in the same file as the repository
dave08
12/30/2020, 11:23 AMziv kesten
12/30/2020, 11:32 AMdave08
12/30/2020, 11:36 AMziv kesten
12/30/2020, 11:42 AMdave08
12/30/2020, 11:43 AMdave08
12/30/2020, 11:44 AMdave08
12/30/2020, 11:48 AMdave08
12/30/2020, 11:48 AMby
to delegate to the db repo.ziv kesten
12/30/2020, 11:58 AMinterface Base {
fun print()
}
class BaseImpl(val x: Int) : Base {
override fun print() { print(x) }
}
class Derived(b: Base) : Base by b
fun main() {
val b = BaseImpl(10)
Derived(b).print()
}
dave08
12/30/2020, 12:21 PMinterface Base {
fun print()
}
class BaseImpl(val x: Int) : Base {
override fun print() = TODO("Not implemented")
fun internalPrint() { print(x) }
}
class Derived(b: BaseImpl) : Base by b {
override fun print() = b.internalPrint() + "---"
}
fun main() {
val b = BaseImpl(10)
Derived(b).print()
}
dave08
12/30/2020, 12:24 PMFlow<List<WatchedShow>>
and the print returns Flow<List<Show>>
dave08
12/30/2020, 12:24 PM