@@ -56,41 +56,40 @@ extension Intersperse: Sequence {
56
56
57
57
extension Intersperse : Collection where Base: Collection {
58
58
public struct Index : Comparable {
59
- enum Kind : Comparable {
60
- case element
59
+ enum Representation : Comparable {
60
+ case element( Base . Index )
61
61
case separator( next: Base . Index )
62
62
}
63
- let index : Base . Index
64
- let kind : Kind
63
+ let representation : Representation
65
64
66
65
public static func < ( lhs: Index , rhs: Index ) -> Bool {
67
- ( lhs. index , lhs . kind ) < ( rhs. index , rhs . kind )
66
+ lhs. representation < rhs. representation
68
67
}
69
68
}
70
69
71
70
public var startIndex : Index {
72
- Index ( index : base. startIndex, kind : . element )
71
+ Index ( representation : . element ( base. startIndex) )
73
72
}
74
73
75
74
public var endIndex : Index {
76
- Index ( index : base. endIndex, kind : . element )
75
+ Index ( representation : . element ( base. endIndex) )
77
76
}
78
77
79
78
public func index( after i: Index ) -> Index {
80
- switch i. kind {
81
- case . element:
82
- let next = base. index ( after: i . index)
79
+ switch i. representation {
80
+ case let . element( index ) :
81
+ let next = base. index ( after: index)
83
82
return next == base. endIndex
84
83
? endIndex
85
- : Index ( index : i . index , kind : . separator( next: next) )
86
- case . separator( let next) :
87
- return Index ( index : next , kind : . element)
84
+ : Index ( representation : . separator( next: next) )
85
+ case let . separator( next) :
86
+ return Index ( representation : . element( next ) )
88
87
}
89
88
}
90
89
91
90
public subscript( position: Index ) -> Element {
92
- switch position. kind {
93
- case . element: return base [ position . index]
91
+ switch position. representation {
92
+ case . element( let index ) : return base [ index]
94
93
case . separator: return separator
95
94
}
96
95
}
@@ -100,13 +99,13 @@ extension Intersperse: BidirectionalCollection
100
99
where Base: BidirectionalCollection
101
100
{
102
101
public func index( before i: Index ) -> Index {
103
- switch i. kind {
104
- case . element where i . index == base. endIndex:
105
- return Index ( index : base. index ( before: i . index) , kind : . element )
106
- case . element:
107
- return Index ( index : base . index ( before : i . index ) , kind : . separator( next: i . index) )
108
- case . separator:
109
- return Index ( index : i . index, kind : . element )
102
+ switch i. representation {
103
+ case let . element( index ) where index == base. endIndex:
104
+ return Index ( representation : . element ( base. index ( before: index) ) )
105
+ case let . element( index ) :
106
+ return Index ( representation : . separator( next: index) )
107
+ case let . separator( next ) :
108
+ return Index ( representation : . element ( base . index ( before : next ) ) )
110
109
}
111
110
}
112
111
}
0 commit comments