Sequence
protocol Sequence
A Sequence can be either finite or infinite.
-
Mechanica
Checks if all the elements in collection satisfiy the given predicate.
Example:
[2, 2, 4, 4].all(matching: {$0 % 2 == 0}) -> true [1, 2, 2, 4].all(matching: {$0 % 2 == 0}) -> falseAttention
the sequence must be finite.Declaration
Swift
public func all(matching predicate: (Element) throws -> Bool) rethrows -> BoolParameters
predicatecondition to evaluate each element against.
Return Value
true when all elements in the array match the specified condition.
-
Mechanica
Checks if no elements in collection satisfiy the given predicate.
Example:
[2, 2, 4].none(matching: {$0 % 2 == 0}) -> false [1, 3, 5].none(matching: {$0 % 2 == 0}) -> trueAttention
the sequence must be finite.Declaration
Swift
public func none(matching predicate: (Element) throws -> Bool) rethrows -> BoolParameters
predicatecondition to evaluate each element against.
Return Value
true when no elements satisfy the specified condition.
-
Mechanica
Checks if any elements in collection satisfiy the given predicate.
Example:
[2, 2, 4].any(matching: {$0 % 2 == 0}) -> false [1, 3, 5, 7].any(matching: {$0 % 2 == 0}) -> trueAttention
the sequence must be finite.Declaration
Swift
public func any(matching predicate: (Element) throws -> Bool) rethrows -> BoolParameters
predicatecondition to evaluate each element against.
Return Value
true when no elements satisfy the specified condition.
-
Mechanica
Returns true if there is at least one element satisfying the given predicate.
Attention
the sequence must be finite.Declaration
Swift
public func hasAny(where predicate: (Element) -> Bool) -> BoolParameters
predicateA closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Returns true if all the elements satisfy the predicate.
Attention
the sequence must be finite.Declaration
Swift
public func hasAll(where predicate: (Element) -> Bool) -> BoolParameters
predicateA closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Attention
the sequence must be finite.Declaration
Swift
public func grouped<Key>(by criteria: (Element) -> (Key)) -> [Key : [Element]] where Key : HashableParameters
criteriaThe criteria closure takes an
Elementand returns its classification.Return Value
A grouped dictionary with the keys that the criteria function returns.
-
Mechanica
Splits
selfinto partitions of a givenlength.Example:
let string = "Hello" string.split(by: 2) -> ["He", "ll", "o"]Attention
the sequence must be finite.Declaration
Swift
public func split(by length: Int) -> [[Element]] -
Mechanica
Returns a sequence that contains no duplicates according to the generic hash and equality comparisons on the keys reuteruned by the given key generating block. If an element occurs multiple times, the later occurrences are discarded
Declaration
Swift
public func distinctElements<Key>(by keyGenerator: (Element) -> Key) -> [Element] where Key : HashableParameters
keyGeneratorThe key generating block.
-
Mechanica
Returns true if the
Sequencecontains all the given elements.Example:
[1, 2, 3, 4, 5].contains([1, 2]) -> true ["h", "e", "l", "l", "o"].contains(["l", "o"]) -> trueAttention
the sequence must be finite.Declaration
Swift
public func contains(_ elements: [Element]) -> Bool -
Mechanica
Returns a collection of tuples where it’s indicated the frequencies of the elements in the sequence.
Attention
the sequence must be finite.Declaration
Swift
public var frequencies: [(Element, Int)] { get } -
Mechanica
Attention
the sequence must be finite.Declaration
Swift
public func hasDuplicates() -> BoolReturn Value
Returns true if the
Sequencecontains duplicates
-
Mechanica
Returns true if the
Sequencecontains an element identical (referential equality) to anobject.Attention
the sequence must be finite.Declaration
Swift
public func containsObjectIdentical(to object: AnyObject) -> Bool
-
Mechanica
Sums of all elements in array.
Example:
[1, 2, 3, 4].sum() -> 10Attention
the sequence must be finite.Declaration
Swift
public func sum() -> Element
Sequence Extension Reference