Collection

protocol Collection : Sequence where Self.SubSequence : Collection
  • SwifterSwift: Performs each closure for each element of collection in parallel.

    array.forEachInParallel { item in
        print(item)
    }
    

    Declaration

    Swift

    public func forEachInParallel(_ each: (Self.Iterator.Element) -> Void)

    Parameters

    each

    closure to run for each element.

  • SwifterSwift: Safe protects the array from out of bounds by use of optional.

    let arr = [1, 2, 3, 4, 5]
    arr[safe: 1] -> 2
    arr[safe: 10] -> nil
    

    Declaration

    Swift

    public subscript(safe index: Index) -> Iterator.Element?

    Parameters

    index

    index of element to access element.

  • SwifterSwift: Random item from array.

    Declaration

    Swift

    public var randomItem: Element?
  • SwifterSwift: Average of all elements in array.

    Declaration

    Swift

    public func average() -> Double

    Return Value

    the average of the array’s elements.