Scala

Scala

Made by DeepSource

Replace filter().isEmpty with !exists() SC-R1007

Anti-pattern
Minor

filter() allows you to select elements from your collection that satisfy the provided condition/predicate. In situations where you need to check if there are any elements satisfying your condition, it is suggested that you directly use !exists() over filter().isEmpty as the former is slightly more efficient, readable, and easy to maintain.

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