Sequence
protocol Sequence
-
Mechanica
Returns true only if all the elements match the
condition
.Declaration
Swift
public func containsOnly(where condition: (Element) -> Bool) -> Bool
-
Mechanica
Returns true if there is at least one element
matching
the predicate.Declaration
Swift
public func hasSomeElements(where predicate: (Element) -> Bool) -> Bool
Parameters
predicate
A 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
match
the predicate.Declaration
Swift
public func hasAllElements(where predicate: (Element) -> Bool) -> Bool
Parameters
predicate
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element is a match.
-
Mechanica
Declaration
Swift
public func grouped<Key>(by criteria: (Element) -> (Key)) -> [Key : [Element]] where Key : Hashable
Parameters
criteria
The criteria closure takes an
Element
and returns its classification.Return Value
A grouped dictionary with the keys that the criteria function returns.
-
Mechanica
Returns the elements count matching a predicate.
Declaration
Swift
public func count(where predicate: (Element) -> Bool) -> Int
Parameters
where
A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be counted or not.
-
Mechanica
Splits
self
into partitions of a givenlength
.Example:
let string = "Hello" string.split(by: 2) -> ["He", "ll", "o"]
Declaration
Swift
public func split(by length: Int) -> [[Element]]
-
Mechanica
Returns true if the
Sequence
contains all the given elements.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.
Declaration
Swift
public var frequencies: [(Element, Int)] { get }
-
Mechanica
Returns true if the
Sequence
contains an element identical (referential equality) to anobject
.Declaration
Swift
public func containsObjectIdentical(to object: AnyObject) -> Bool