Array

struct Array<Element> : RandomAccessCollection, MutableCollection
  • Get a sub array from range of index

    Declaration

    Swift

    public func get(at range: ClosedRange<Int>) -> Array
  • Checks if array contains at least 1 item which type is same with given element’s type

    Declaration

    Swift

    public func containsType<T>(of element: T) -> Bool
  • Decompose an array to a tuple with first element and the rest

    Declaration

    Swift

    public func decompose() -> (head: Iterator.Element, tail: SubSequence)?
  • Iterates on each element of the array with its index. (Index, Element)

    Declaration

    Swift

    public func forEachEnumerated(_ body: @escaping (_ offset: Int, _ element: Element) -> Void)
  • Gets the object at the specified index, if it exists.

    Declaration

    Swift

    public func get(at index: Int) -> Element?
  • Prepends an object to the array.

    Declaration

    Swift

    public mutating func insertFirst(_ newElement: Element)
  • Returns a random element from the array.

    Declaration

    Swift

    public func random() -> Element?
  • Reverse the given index. i.g.: reverseIndex(2) would be 2 to the last

    Declaration

    Swift

    public func reverseIndex(_ index: Int) -> Int?
  • Shuffles the array in-place using the Fisher-Yates-Durstenfeld algorithm.

    Declaration

    Swift

    public mutating func shuffle()
  • Shuffles copied array using the Fisher-Yates-Durstenfeld algorithm, returns shuffled array.

    Declaration

    Swift

    public func shuffled() -> Array
  • Returns an array with the given number as the max number of elements.

    Declaration

    Swift

    public func takeMax(_ n: Int) -> Array
  • Checks if test returns true for all the elements in self

    Declaration

    Swift

    public func testAll(_ body: @escaping (Element) -> Bool) -> Bool
  • Checks if all elements in the array are true or false

    Declaration

    Swift

    public func testAll(is condition: Bool) -> Bool
  • Lookup value within array with check closure

    Declaration

    Swift

    public func lookup(_ check: (Element) -> Bool) -> Element?

    Parameters

    check

    Check element closure

    Return Value

    Found element when founded or nil, when not

  • Transform Array to Dictionary

    Declaration

    Swift

    public func map<K, V>(_ transform: (Element) -> (key: K, value: V)) -> [K: V]

    Parameters

    transform

    Transform closure

    Return Value

    Result dictionary

  • Transform Array to Dictionary (without nil transforms)

    Declaration

    Swift

    public func mapSkipNil<K, V>(_ transform: (Element) -> (key: K, value: V)?) -> [K: V]

    Parameters

    transform

    Transform closure

    Return Value

    Result dictionary

  • Transform Array (without nil transforms)

    Declaration

    Swift

    public func mapSkipNil<V>(_ transform: (Element) -> V?) -> [V]

    Parameters

    transform

    Transform closure

    Return Value

    Result array

  • Check element existance

    Declaration

    Swift

    public func exists(_ check: (Element) -> Bool) -> Bool

    Parameters

    check

    Check closure

    Return Value

    True when exists, false when not

  • Remove first founded object from the array, that equals to scecified object (see Equatable protocol)

    Declaration

    Swift

    public mutating func removeObject<U: Equatable>(_ object: U) -> Bool

    Parameters

    object

    Object to remove

  • Checks if the main array contains the parameter array

    Declaration

    Swift

    public func contains(_ array: [Element]) -> Bool
  • Checks if self contains a list of items.

    Declaration

    Swift

    public func contains(_ elements: Element...) -> Bool
  • Returns the indexes of the object

    Declaration

    Swift

    public func indexes(of element: Element) -> [Int]
  • Returns the last index of the object

    Declaration

    Swift

    public func lastIndex(of element: Element) -> Int?
  • Removes the first given object

    Declaration

    Swift

    public mutating func removeFirst(_ element: Element)
  • Removes all occurrences of the given object(s), at least one entry is needed.

    Declaration

    Swift

    public mutating func removeAll(_ firstElement: Element?, _ elements: Element...)
  • Removes all occurrences of the given object(s)

    Declaration

    Swift

    public mutating func removeAll(_ elements: [Element])
  • Difference of self and the input arrays.

    Declaration

    Swift

    public func difference(_ values: [Element]...) -> [Element]
  • Intersection of self and the input arrays.

    Declaration

    Swift

    public func intersection(_ values: [Element]...) -> Array
  • Union of self and the input arrays.

    Declaration

    Swift

    public func union(_ values: [Element]...) -> Array
  • Returns an array consisting of the unique elements in the array

    Declaration

    Swift

    public func unique() -> Array
  • Removes all occurrences of the given object(s)

    Declaration

    Swift

    public mutating func removeAll(_ elements: [Element])