Functions

The following functions are available globally.

  • Returns a randomly chosen element from a collection.

    Declaration

    Swift

    public func sample() -> Generator.Element?

    Return Value

    An element or nil if the collection is empty.

  • Finds the first element in a collection that is true for a given callback.

    Declaration

    Swift

    public func find(callback: (Generator.Element) -> Bool) -> Generator.Element?

    Parameters

    callback

    The callback to check each element against.

    Return Value

    An element or nil if no element satisfied the callback.

  • Returns elements from a collection with multiple provided indices. If the collection has no elements at any of the provided indices, the returned array will be empty.

    Declaration

    Swift

    public func at(indices: [Index]) -> [Generator.Element]

    Parameters

    indices

    The indices of the desired elements

    Return Value

    An array of extracted elements.

  • Determines if a callback is true for at least one element in a collection.

    Declaration

    Swift

    public func some(callback: (Generator.Element) -> Bool) -> Bool

    Parameters

    callback

    The callback to check each element against.

    Return Value

    True or false.

  • Determines if a callback is true for every element in a collection.

    Declaration

    Swift

    public func every(callback: (Generator.Element) -> Bool) -> Bool

    Parameters

    callback

    The callback to check each element against.

    Return Value

    True or false.

  • Determines if a callback is true for zero elements in a collection.

    Declaration

    Swift

    public func none(callback: (Generator.Element) -> Bool) -> Bool

    Parameters

    callback

    The callback to check each element against.

    Return Value

    True or false.