Filtering

Remove duplicated elements or strip the nil values from a sequence or collection.

Filtering.md

Overview

Use the uniquing methods to remove duplicates from a sequence or collection, or to remove elements that have a duplicated property.

let numbers = [1, 2, 3, 3, 2, 3, 3, 2, 2, 2, 1]

let unique = numbers.uniqued()
// Array(unique) == [1, 2, 3]

The compacted() method removes all nil values from a sequence or collection of optionals:

let array: [Int?] = [10, nil, 30, nil, 2, 3, nil, 5]
let withNoNils = array.compacted()
// Array(withNoNils) == [10, 30, 2, 3, 5]

Uniquing Elements

Filtering out nil Elements

Supporting Types