quick question, im trying to use the find method, ...
# announcements
x
quick question, im trying to use the find method, but for some reason it returns
Copy code
List<Test?>
and I want it to be just a List<Test>. how do I prevent the type of the elements in the list to be nullable? I want it to be an empty list worst case scenario
s
what’s the type of the source list?
x
Map<Long, List<Test>>
so im doing
Copy code
foo.map { (a, b) -> b.find( it.bar == condition)}
s
you want a function that works on the map’s values
x
can you elaborate please?
s
So, you have this map, you want to find all the
Test
instances inside of it that match a certain condition, right?
x
correct
and if there are none, worst case scenario, i just want it to be an empty list of Test, not an emptyList of null
s
you’d want something more like
Copy code
foo.values.flatten().filter { it.var == condition }
if your map is particularly large, you’ll want to convert to and from a
Sequence<T>
as needed
I don’t particularly like seeing
.flatten().filter()
myself but there is no
flatFilter()
so 😅
x
yeah... i prefer to just use fold
😛
thank you man
👍 1