Pattern: Use of .filter { }.last
instead of .last(where:)
Issue: -
Prefer using .last(where:)
over .filter { }.last
in collections.
Examples of correct code:
kinds.filter(excludingKinds.contains).isEmpty && kinds.last == .identifier
myList.last(where: { $0 % 2 == 0 })
match(pattern: pattern).filter { $0.last == .identifier }
(myList.filter { $0 == 1 }.suffix(2)).last
collection.filter("stringCol = '3'").last
Examples of incorrect code:
↓myList.filter { $0 % 2 == 0 }.last
↓myList.filter({ $0 % 2 == 0 }).last
↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).last
↓myList.map { $0 + 1 }.filter({ $0 % 2 == 0 }).last?.something()
↓myList.filter(someFunction).last
↓myList.filter({ $0 % 2 == 0 })
.last
(↓myList.filter { $0 == 1 }).last