```suspend fun sleepSort(list: List<Int>): L...
# coroutines
i
Copy code
suspend fun sleepSort(list: List<Int>): List<Int> {

    val listInt = listOf(1, 2, 3)
    val listDeferred = list.map {
        GlobalScope.async {
            println("start $it")
        }
    }
    listDeferred.first().await()

    return listOf()
}
The above code gives me this result
Copy code
start 1
start 2
start 3
I wonder why all deferred jobs are launched instead of jus the first one 🤔
o
list.map
is not lazy -- it returns a List itself
if you want a lazily evaluated mapping, use
.asSequence()
first
i
ahh, right, thx
a
or specify CoroutineStart.LAZY on async
👍 1