compacted

Returns a new Collection that iterates over every non-nil element from the original Collection.

Compacted.swift:169
func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped> where Self.Element == Unwrapped?

Returns

A Collection where the element is the unwrapped original element and iterates over every non-nil element from the original Collection.

Produces the same result as c.compactMap { $0 }.

let c = [1, nil, 2, 3, nil]
for num in c.compacted() {
    print(num)
}
// 1
// 2
// 3

Complexity: O(n) where n is the number of elements in the original Collection.