Creates a sequence of pairs built out of two underyling sequences.
In the Zip2Sequence instance returned by this function, the elements of
the ith pair are the ith elements of each underlying sequence. The
following example uses the zip(_:_:) function to iterate over an array
of strings and a countable range at the same time:
letwords= ["one", "two", "three", "four"]
letnumbers= 1...4
for(word, number) inzip(words, numbers) {
print("\(word): \(number)")
}
// Prints "one: 1"
// Prints "two: 2
// Prints "three: 3"
// Prints "four: 4"
If the two sequences passed to zip(_:_:) are different lengths, the
resulting sequence is the same length as the shorter sequence. In this
example, the resulting array is the same length as words:
Parameters:sequence1: The first sequence or collection to zip.
sequence2: The second sequence or collection to zip.
Returns: A sequence of tuple pairs, where the elements of each pair are
corresponding elements of sequence1 and sequence2.
Creates a sequence of pairs built out of two underyling sequences.
In the
Zip2Sequence
instance returned by this function, the elements of the ith pair are the ith elements of each underlying sequence. The following example uses thezip(_:_:)
function to iterate over an array of strings and a countable range at the same time:If the two sequences passed to
zip(_:_:)
are different lengths, the resulting sequence is the same length as the shorter sequence. In this example, the resulting array is the same length aswords
:Parameters: sequence1: The first sequence or collection to zip. sequence2: The second sequence or collection to zip. Returns: A sequence of tuple pairs, where the elements of each pair are corresponding elements of
sequence1
andsequence2
.Declaration
func
zip
<
Sequence1
:
Sequence
,
Sequence2
:
Sequence
>
(
_
sequence1
:
Sequence1
,
_
sequence2
:
Sequence2
) -
>
Zip2Sequence
<
Sequence1
,
Sequence2
>