Slide 28
Slide 28 text
@Test
fun testFlowSection() = runBlockingTest {
listOf(Section("Title", (1..5).toList())).asFlow()
.cancellable()
.flatMapLatest { section ->
section.list.asFlow().cancellable()
.map {
"Item $it"
}
.toListFlow()
.map {
NewSection(section.title, it)
}
.toListFlow()
}
.onEach {
println("New list $it")
}
.launchIn(this)
}
@Test
fun testRxJavaSection() {
val items = listOf(Section("Title", (1..5).toList()))
Observable.fromIterable(items)
.switchMapSingle { section ->
Observable.fromIterable(section.list)
.map {
"Item $it"
}
.toList()
.map {
NewSection(section.title, it)
}
.toList()
}
.subscribe { t1, _ ->
println("t1 $t1")
}
}
@Test
fun testRxJavaSection() {
val items = listOf(Section("Title", (1..5).toList()))
.switchMapSingle { section ->
Observable.fromIterable(section.list)
.toList()
.map {
NewSection(section.title, it)
}
.toList()
}
}
@Test
fun testFlowSection() = runBlockingTest {
.flatMapLatest { section ->
section.list.asFlow().cancellable()
.toListFlow()
.map {
NewSection(section.title, it)
}
.toListFlow()
}
}
Flow - streamਵ۽ যоӝ
data class Section(val title: String, val list: List)
data class NewSection(val title: String, val list: List)