Scala

Scala

Made by DeepSource

Replace filter().size with count() SC-R1008

Anti-pattern
Minor

filter() allows you to select elements from your collection that satisfy the provided condition/predicate. In situations where you need to count the number of elements satisfying your condition, it is suggested that you directly use count() over filter().size as the former is slightly more efficient, readable and easy to maintain.

// count even numbers
nums.filter(n => n % 2 == 0).size     // get's the job done
nums.count(n => n % 2 == 0)           // that's better