|
13 | 13 | /// A sequence of pairs built out of two underlying sequences, where
|
14 | 14 | /// the elements of the `i`th pair are the `i`th elements of each
|
15 | 15 | /// underlying sequence.
|
16 |
| -public func zip<Sequence1 : SequenceType, Sequence2 : SequenceType>( |
17 |
| - sequence1: Sequence1, _ sequence2: Sequence2 |
18 |
| -) -> Zip2<Sequence1, Sequence2> { |
19 |
| - return Zip2(sequence1, sequence2) |
| 16 | +public func zip<S0: SequenceType, S1: SequenceType>( |
| 17 | + s0: S0, _ s1: S1 |
| 18 | +) -> Zip2<S0, S1> { |
| 19 | + return Zip2(s0, s1) |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | /// A generator for the `Zip2` sequence
|
23 | 23 | public struct ZipGenerator2<
|
24 |
| - Generator1 : GeneratorType, Generator2 : GeneratorType |
| 24 | + E0 : GeneratorType, E1 : GeneratorType |
25 | 25 | > : GeneratorType {
|
26 | 26 | /// The type of element returned by `next()`.
|
27 |
| - public typealias Element = (Generator1.Element, Generator2.Element) |
| 27 | + public typealias Element = (E0.Element,E1.Element) |
28 | 28 |
|
29 | 29 | /// Construct around a pair of underlying generators.
|
30 |
| - public init(_ generator1: Generator1, _ generator2: Generator2) { |
31 |
| - baseStreams = (generator1, generator2) |
| 30 | + public init(_ e0: E0, _ e1: E1) { |
| 31 | + baseStreams = (e0,e1) |
32 | 32 | }
|
33 | 33 |
|
34 | 34 | /// Advance to the next element and return it, or `nil` if no next
|
@@ -61,37 +61,36 @@ public struct ZipGenerator2<
|
61 | 61 | return .Some((e0!, e1!))
|
62 | 62 | }
|
63 | 63 |
|
64 |
| - internal var _baseStreams: (Generator1, Generator2) |
65 |
| - internal var _reachedEnd: Bool = false |
| 64 | + var baseStreams: (E0, E1) |
| 65 | + var reachedEnd: Bool = false |
66 | 66 | }
|
67 | 67 |
|
68 | 68 | /// A sequence of pairs built out of two underlying sequences, where
|
69 | 69 | /// the elements of the `i`th pair are the `i`th elements of each
|
70 | 70 | /// underlying sequence.
|
71 |
| -public struct Zip2<Sequence1 : SequenceType, Sequence2 : SequenceType> |
72 |
| - : SequenceType { |
73 |
| - |
74 |
| - public typealias Stream1 = Sequence1.Generator |
75 |
| - public typealias Stream2 = Sequence2.Generator |
76 |
| - |
| 71 | +public struct Zip2<S0: SequenceType, S1: SequenceType> : SequenceType |
| 72 | +{ |
| 73 | + public typealias Stream1 = S0.Generator |
| 74 | + public typealias Stream2 = S1.Generator |
| 75 | + |
77 | 76 | /// A type whose instances can produce the elements of this
|
78 | 77 | /// sequence, in order.
|
79 | 78 | public typealias Generator = ZipGenerator2<Stream1, Stream2>
|
80 | 79 |
|
81 |
| - /// Construct an instance that makes pairs of elements from `sequence1` and |
82 |
| - /// `sequence2`. |
83 |
| - public init(_ sequence1: Sequence1, _ sequence2: Sequence2) { |
84 |
| - _sequences = (sequence1, sequence2) |
| 80 | + /// Construct an instance that makes pairs of elements from `s0` and |
| 81 | + /// `s1`. |
| 82 | + public init(_ s0: S0, _ s1: S1) { |
| 83 | + sequences = (s0,s1) |
85 | 84 | }
|
86 | 85 |
|
87 | 86 | /// Return a *generator* over the elements of this *sequence*.
|
88 | 87 | ///
|
89 | 88 | /// - complexity: O(1)
|
90 | 89 | public func generate() -> Generator {
|
91 | 90 | return Generator(
|
92 |
| - _sequences.0.generate(), |
93 |
| - _sequences.1.generate()) |
| 91 | + sequences.0.generate(), |
| 92 | + sequences.1.generate()) |
94 | 93 | }
|
95 | 94 |
|
96 |
| - internal let _sequences: (Sequence1, Sequence2) |
| 95 | + var sequences: (S0,S1) |
97 | 96 | }
|
0 commit comments