Returns a new collection of the same type containing, in order, the elements of the original collection that satisfy the given predicate.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 8.0+
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be included in the returned collection.
A collection of the elements that
In this example,
filter(_:) is used to include only names shorter than five characters.
Complexity: O(n), where n is the length of the collection.