PairIterator
public struct PairIterator<T, U> : Sequence, IteratorProtocol where T : Sequence, U : Sequence
An iterator that iterates over pairs of elements in firstSequence
and secondSequence
.
secondSequence
must not destructively consume its contents.
For example, the first element generated is (firstSequence[0], secondSequence[0])
, the second element
is (firstSequence[0], secondSequence[1])
, all the way to (firstSequence[0]. secondSequence.last)
,
at which point the next element is (firstSequence[1], secondSequence[0])
.
for (x, y) in pairs(firstSequence, secondSequence) {
//...
}
is equivalent to
for x in firstSequence {
for y in secondSequence {
//...
}
}
-
Initializes a PairIterator instance.
- paramter firstSequence: The first sequence to iterate over.
Declaration
Swift
public init(firstSequence: T, secondSequence: U)
Parameters
secondSequence
The second sequence to iterate over.
-
Returns the next element in the sequence, or
nil
if the sequence is done iterating.Declaration
Swift
public mutating func next() -> (T.Element, U.Element)?
Return Value
A tuple containing an element in the first sequence and an element in the second sequence.
-
Returns an iterator that can be
Declaration
Swift
public func makeIterator() -> PairIterator<T, U>