Klitos Kyriacou
06/26/2022, 12:03 PM(list1 + list2).firstOrNull { it.matches(something) }
but without eagerly iterating the lists and creating a new list from them?
In other words, exactly like Guava's FluentIterable.concat(list1, list2)
but more Kotlin-idiomatic?Youssef Shoaib [MOD]
06/26/2022, 12:25 PMsequence {
yieldAll(list1)
yieldAll(list2)
}.firstOrNull {...}
Klitos Kyriacou
06/26/2022, 12:53 PMsequenceOf(list1, list2).flatten()
is even a little bit shorter. If I wanted the exact behaviour of FluentIterable.concat
I would have to add .asIterable()
. It's just a little bit disappointing that sequenceOf(list, list2).flatten().asIterable()
is longer than FluentIterable.concat(list1, list2)
but most of the time I can take it directly as a Sequence, so I can omit the .asIterable()
.Youssef Shoaib [MOD]
06/26/2022, 12:56 PM(list1.asSequence() + list2).asIterable()
Klitos Kyriacou
06/26/2022, 1:03 PMasSequence
on only one of the lists makes the code less elegant)Youssef Shoaib [MOD]
06/26/2022, 1:15 PMKlitos Kyriacou
06/26/2022, 1:24 PMYoussef Shoaib [MOD]
06/26/2022, 1:30 PMnkiesel
06/26/2022, 6:31 PM