https://kotlinlang.org logo
Title
u

ursus

01/20/2019, 4:17 AM
for (lookupTask in lookupTasks) {
    val serverUrl = lookupTask.execute(domain, username, password)
    if (serverUrl != null) {
        return serverUrl
    }
}
return null
p

Pavlo Liapota

01/20/2019, 8:59 AM
return lookupTasks
	.asSequence()
	.mapNotNull { it.execute(domain, username, password) }
	.firstOrNull()
👍 2
u

ursus

01/20/2019, 3:14 PM
doesnt really shortcut it, right?
a

Alowaniak

01/20/2019, 7:37 PM
what do you mean with "doesn't really shortcut it"? It's a sequence so it only does the mapping until it gets the first non null
u

ursus

01/21/2019, 3:51 PM
really? Ill investigate, because im pretty sure normal list.mapNotNull does all the items and skips the null ones
a

Alowaniak

01/21/2019, 3:53 PM
Yes, that's the case with a normal list or w/e. But that's why @Pavlo Liapota had
asSequence()
. Because they are a "lazy collection" like java's
Stream
See https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/index.html