Array

public extension Array
extension Array: EmptyValueRepresentable
extension Array: Emptyable
extension Array: ScopeFunctions
public extension Array where Element: Equatable

Public Functions

  • Returns a subarray starting at index, extending backwards at most lengthelements and forwards at most length elements for a subarray of at most (length * 2) + 1 elements.

    let tmp = [1, 2, 3, 4, 5]
    let retval = tmp.subarrayWithMiddleIndex(1, length: 2)
    
    // do something with retval which is [1, 2, 3, 4]
    

    Declaration

    Swift

    func subarrayWithMiddleIndex(_ index: Int, length: Int) -> [Element]

    Parameters

    index

    The middle anchor index

    length

    The number of elements to extend past index in either direction

    Return Value

    The subarray

Public Properties

  • Declaration

    Swift

    public static var emptyValue: [Element] { get }

Available where Element: Equatable

  • Calls through to Array.subarrayWithMiddleIndex(_:length:) after determining the index of value.

    let tmp = ["one", "two", "three", "four", "five"]
    let retval = tmp.subarrayWithMiddleElement("two", length: 2)
    
    // do something with retval which is ["one", "two", "three", "four"]
    

    Declaration

    Swift

    func subarrayWithMiddleElement(_ value: Element, length: Int) -> [Element]

    Parameters

    value

    The middle anchor element

    length

    The number of elements to extend past the index of value in either direction

    Return Value

    The subarray