Sequence

extension Sequence
  • Returns a sequence filtered using the property accessed by the key path.

    Declaration

    Swift

    public func filtered(
        by keyPath: KeyPath<Element, Bool>
    ) -> [Self.Element]

    Parameters

    keyPath

    Required. The key path to a property of type Bool.

  • Returns an array of the sequence’s elements sorted by the specified key path.

    Declaration

    Swift

    public func sorted<T: Comparable>(
        by keyPath: KeyPath<Element, T>,
        reversed: Bool = false
    ) -> [Self.Element]

    Parameters

    keyPath

    Required. The key path to a Comparable property on the sequence’s element.

    reversed

    Optional. Whether to sort the sequence’s elements in ascending or descending order. Default is false (ascending).

  • Returns an array of elements

    Declaration

    Swift

    public func map<T>(_ keyPath: KeyPath<Element, T>) -> [T]

    Parameters

    keyPath

    Required. The key path to a property on the sequence’s element.