1
- ////===--- EitherSequence .swift - A sequence type-erasing two sequences -----===//
1
+ ////===--- _EitherSequence .swift - A sequence type-erasing two sequences -----===//
2
2
////
3
3
//// This source file is part of the Swift.org open source project
4
4
////
12
12
13
13
// Not public stdlib API, currently used in Mirror.children implementation.
14
14
15
- internal enum Either < Left, Right> {
15
+ internal enum _Either < Left, Right> {
16
16
case left( Left ) , right( Right )
17
17
}
18
18
19
- extension Either {
19
+ extension _Either {
20
20
internal init ( _ left: Left , or other: Right . Type ) { self = . left( left) }
21
21
internal init ( _ left: Left ) { self = . left( left) }
22
22
internal init ( _ right: Right ) { self = . right( right) }
23
23
}
24
24
25
- extension Either : Equatable where Left: Equatable , Right: Equatable {
25
+ extension _Either : Equatable where Left: Equatable , Right: Equatable {
26
26
internal static func == ( lhs: Self , rhs: Self ) -> Bool {
27
27
switch ( lhs, rhs) {
28
28
case let ( . left( l) , . left( r) ) : return l == r
@@ -32,7 +32,7 @@ extension Either: Equatable where Left: Equatable, Right: Equatable {
32
32
}
33
33
}
34
34
35
- extension Either : Comparable where Left: Comparable , Right: Comparable {
35
+ extension _Either : Comparable where Left: Comparable , Right: Comparable {
36
36
internal static func < ( lhs: Self , rhs: Self ) -> Bool {
37
37
switch ( lhs, rhs) {
38
38
case let ( . left( l) , . left( r) ) : return l < r
@@ -51,25 +51,25 @@ extension Either: Comparable where Left: Comparable, Right: Comparable {
51
51
/// AnySequence, giving you a fast path for the known one.
52
52
///
53
53
/// If you have 3+ types to erase, you can nest them.
54
- typealias EitherSequence < L: Sequence , R: Sequence > =
55
- Either < L , R > where L. Element == R. Element
54
+ typealias _EitherSequence < L: Sequence , R: Sequence > =
55
+ _Either < L , R > where L. Element == R. Element
56
56
57
- extension EitherSequence {
57
+ extension _EitherSequence {
58
58
internal struct Iterator {
59
59
var left : Left . Iterator ?
60
60
var right : Right . Iterator ?
61
61
}
62
62
}
63
63
64
- extension Either . Iterator : IteratorProtocol {
64
+ extension _Either . Iterator : IteratorProtocol {
65
65
internal typealias Element = Left . Element
66
66
67
67
internal mutating func next( ) -> Element ? {
68
68
left? . next ( ) ?? right? . next ( )
69
69
}
70
70
}
71
71
72
- extension EitherSequence : Sequence {
72
+ extension _EitherSequence : Sequence {
73
73
internal typealias Element = Left . Element
74
74
75
75
internal func makeIterator( ) -> Iterator {
@@ -82,12 +82,12 @@ extension EitherSequence: Sequence {
82
82
}
83
83
}
84
84
85
- internal typealias EitherCollection <
85
+ internal typealias _EitherCollection <
86
86
T: Collection , U: Collection
87
- > = EitherSequence < T , U > where T. Element == U. Element
87
+ > = _EitherSequence < T , U > where T. Element == U. Element
88
88
89
- extension EitherCollection : Collection {
90
- internal typealias Index = Either < Left . Index , Right . Index >
89
+ extension _EitherCollection : Collection {
90
+ internal typealias Index = _Either < Left . Index , Right . Index >
91
91
92
92
internal var startIndex : Index {
93
93
switch self {
@@ -107,15 +107,15 @@ extension EitherCollection: Collection {
107
107
switch ( self , position) {
108
108
case let ( . left( s) , . left( i) ) : return s [ i]
109
109
case let ( . right( s) , . right( i) ) : return s [ i]
110
- default : fatalError ( " EitherCollecton : Sequence used with other index type" )
110
+ default : fatalError ( " _EitherCollecton : Sequence used with other index type" )
111
111
}
112
112
}
113
113
114
114
internal func index( after i: Index ) -> Index {
115
115
switch ( self , i) {
116
116
case let ( . left( s) , . left( i) ) : return . left( s. index ( after: i) )
117
117
case let ( . right( s) , . right( i) ) : return . right( s. index ( after: i) )
118
- default : fatalError ( " EitherCollecton : wrong type of index used" )
118
+ default : fatalError ( " _EitherCollecton : wrong type of index used" )
119
119
}
120
120
}
121
121
@@ -129,15 +129,15 @@ extension EitherCollection: Collection {
129
129
return s. index ( i, offsetBy: distance, limitedBy: limit) . map { . left( $0) }
130
130
case let ( . right( s) , . right( i) , . right( limit) ) :
131
131
return s. index ( i, offsetBy: distance, limitedBy: limit) . map { . right( $0) }
132
- default : fatalError ( " EitherCollecton : wrong type of index used" )
132
+ default : fatalError ( " _EitherCollecton : wrong type of index used" )
133
133
}
134
134
}
135
135
136
136
internal func index( _ i: Index , offsetBy distance: Int ) -> Index {
137
137
switch ( self , i) {
138
138
case let ( . left( s) , . left( i) ) : return . left( s. index ( i, offsetBy: distance) )
139
139
case let ( . right( s) , . right( i) ) : return . right( s. index ( i, offsetBy: distance) )
140
- default : fatalError ( " EitherCollecton : wrong type of index used" )
140
+ default : fatalError ( " _EitherCollecton : wrong type of index used" )
141
141
}
142
142
}
143
143
@@ -147,32 +147,32 @@ extension EitherCollection: Collection {
147
147
return s. distance ( from: i, to: j)
148
148
case let ( . right( s) , . right( i) , . right( j) ) :
149
149
return s. distance ( from: i, to: j)
150
- default : fatalError ( " EitherCollecton : wrong type of index used" )
150
+ default : fatalError ( " _EitherCollecton : wrong type of index used" )
151
151
}
152
152
}
153
153
}
154
154
155
- internal typealias EitherBidirectionalCollection <
155
+ internal typealias _EitherBidirectionalCollection <
156
156
L: BidirectionalCollection , R: BidirectionalCollection
157
- > = Either < L , R > where L. Element == R. Element
157
+ > = _Either < L , R > where L. Element == R. Element
158
158
159
- extension EitherBidirectionalCollection : BidirectionalCollection {
159
+ extension _EitherBidirectionalCollection : BidirectionalCollection {
160
160
internal func index( before i: Index ) -> Index {
161
161
switch ( self , i) {
162
162
case let ( . left( s) , . left( i) ) : return . left( s. index ( before: i) )
163
163
case let ( . right( s) , . right( i) ) : return . right( s. index ( before: i) )
164
- default : fatalError ( " EitherCollecton : wrong type of index used" )
164
+ default : fatalError ( " _EitherCollecton : wrong type of index used" )
165
165
}
166
166
}
167
167
}
168
168
169
- internal typealias EitherRandomAccessCollection <
169
+ internal typealias _EitherRandomAccessCollection <
170
170
L: RandomAccessCollection , R: RandomAccessCollection
171
- > = Either < L , R > where L. Element == R. Element
171
+ > = _Either < L , R > where L. Element == R. Element
172
172
173
- extension EitherRandomAccessCollection : RandomAccessCollection { }
173
+ extension _EitherRandomAccessCollection : RandomAccessCollection { }
174
174
175
- extension Either {
175
+ extension _Either {
176
176
init < T, C: Collection > (
177
177
_ collection: C
178
178
) where Right == AnyCollection < T > , C. Element == T {
@@ -182,7 +182,7 @@ extension Either {
182
182
183
183
extension AnyCollection {
184
184
init < L: Collection , R: Collection > (
185
- _ other: Either < L , R >
185
+ _ other: _Either < L , R >
186
186
) where L. Element == Element , R. Element == Element {
187
187
// Strip away the Either and put the actual collection into the existential,
188
188
// trying to use the custom initializer from another AnyCollection.
0 commit comments