svenjacobs
04/23/2020, 12:09 PMlist.asSequence().withIndex().find { some predicate }
streetsofboston
04/23/2020, 12:13 PMasSequence()
is necessary...svenjacobs
04/23/2020, 12:18 PMasSequence()
makes sense because then the values are computed lazily. So if the predicate matches the second item of the list out of 500, then only two IndexedValue
needed to be created and 498 IndexedValue
where never created 🙂marstran
04/23/2020, 12:41 PMwithIndex
on a list actually returns a lazy iterable: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/with-index.htmlsvenjacobs
04/23/2020, 12:43 PMSequence
has it's own implementation of withIndex.marstran
04/23/2020, 12:44 PMIterable
that wraps each element ...".svenjacobs
04/23/2020, 12:44 PMIterable
you're correct, but that's the reason why I convert the list to a Sequence
firstmarstran
04/23/2020, 12:44 PMlist.withIndex()
is just as lazy as the sequence.marstran
04/23/2020, 12:45 PMsvenjacobs
04/23/2020, 12:46 PM