rspec/rules/S4173/swift/rule.adoc

28 lines
628 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
If you only want one instance that matches certain criteria out of a collection, it's far more efficient to grab the first matching item than it is to fully filter the collection for your criteria and then only use a single value.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
let one = arr.filter { $0.containsString("yo") }.first // Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
let one = arr.first(where: { $0.containsString("yo") })
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]