dave08
01/17/2019, 2:57 PMmapNotNull
...? It might be nice to add such extensions in kotlinx.coroutines that take suspend lambdas no (I don't know how this would work though)? Or use inline functions...withoutclass
01/17/2019, 3:11 PM@Test
suspend fun doThing() {
val listOfNumbers = listOf(1,null,null,4,5,6)
listOfNumbers.mapNotNull {
alterInt(it)
}
}
private suspend fun alterInt(number: Int?): Int? {
return number?.let {
delay(500)
number + number
}
}
withoutclass
01/17/2019, 3:11 PMmarstran
01/17/2019, 3:12 PMsuspend fun doRequest(n: Int): Int? =
n.takeIf { n % 2 == 0 }
.also { delay(100) }
fun CoroutineScope.work() = launch {
val responses = (0..5).mapNotNull {
doRequest(it)
}
println(responses)
}
suspend fun main() {
coroutineScope {
work()
}
}
dave08
01/17/2019, 4:07 PMasSequence()
dave08
01/17/2019, 4:07 PMelizarov
01/17/2019, 4:09 PMdave08
01/17/2019, 4:13 PMdave08
01/17/2019, 4:15 PMTransformingSequence
dave08
01/17/2019, 4:16 PMmarstran
01/17/2019, 4:16 PMmapNotNull
. It would be at the point where you do the terminal operation.marstran
01/17/2019, 4:17 PMdave08
01/17/2019, 4:18 PMdave08
01/17/2019, 4:21 PMelizarov
01/18/2019, 4:16 PM