Guys, is ``` collections .filter { it.conditionA ...
# announcements
v
Guys, is
Copy code
collections
.filter { it.conditionA }
.filter { it.conditionB }
.filter { it.conditionC }
performing same as
Copy code
collections
.filter { it.conditionA || it.conditionB || it.conditionC }
? I wonder if 1st block will be 3x times slower or not?
n
shouldn’t it be
it.conditionA && it.conditionB && it.conditionC
? 🙂
👍 1
c
first one will generate 3 loops, second one - 1 loop.
also, since you're using collections instead of sequences you'll also have 3 collections created on each filter in the first, and only one in the second.
v
Yeah, I meant to use &&.
a
@viliusk depends on what type
collections
is. If its a `List<T>`you end up with 3 loops, if its a
Sequence<T>
you get a single loop
👍 3
p
All that being said I find the first version more readable and I always write code readable first, maintainable second, performant third. It's very possible that
collections
will always have so few elements that the performance impact is negligible. Or maybe the bottleneck is elsewhere.
👍 1