Marc Knaup
09/01/2020, 2:23 PMnull
if it completes?
interface Foo
interface FooProvider { fun provide(): Foo? }
fun provideFoo(providers: List<FooProvider>): Foo? {
for (provider in providers)
provider.provide()?.let { return it }
return null
}
I miss something like providers.firstNonNullMapped { it.provide() }
(and with a better name).arekolek
09/01/2020, 2:36 PMproviders.asSequence().mapNotNull(FooProvider::provide).firstOrNull()
?Marc Knaup
09/01/2020, 2:40 PMShawn
09/01/2020, 2:52 PMMatteo Mirk
09/01/2020, 3:22 PMTobias Berger
09/01/2020, 10:05 PMmapFirstNotNull
extension method that does the returning loopMike
09/04/2020, 8:54 PMasSequence
avoids creating intermediary collections IIRC.