@@ -126,7 +126,7 @@ extension AdjacentPairsSequence: Sequence {
126126}
127127
128128extension AdjacentPairsSequence : LazySequenceProtocol
129- where Base: LazySequenceProtocol { }
129+ where Base: LazySequenceProtocol { }
130130
131131/// A collection of adjacent pairs of elements built from an underlying
132132/// collection.
@@ -143,7 +143,8 @@ public struct AdjacentPairsCollection<Base: Collection> {
143143 @inlinable
144144 internal init ( base: Base ) {
145145 self . base = base
146- self . secondBaseIndex = base. isEmpty
146+ self . secondBaseIndex =
147+ base. isEmpty
147148 ? base. endIndex
148149 : base. index ( after: base. startIndex)
149150 }
@@ -154,7 +155,7 @@ extension AdjacentPairsCollection {
154155 public struct Index : Comparable {
155156 @usableFromInline
156157 internal var first : Base . Index
157-
158+
158159 @usableFromInline
159160 internal var second : Base . Index
160161
@@ -168,7 +169,7 @@ extension AdjacentPairsCollection {
168169 public static func == ( lhs: Index , rhs: Index ) -> Bool {
169170 lhs. first == rhs. first
170171 }
171-
172+
172173 @inlinable
173174 public static func < ( lhs: Index , rhs: Index ) -> Bool {
174175 lhs. first < rhs. first
@@ -183,7 +184,7 @@ extension AdjacentPairsCollection: Collection {
183184 first: secondBaseIndex == base. endIndex ? base. endIndex : base. startIndex,
184185 second: secondBaseIndex)
185186 }
186-
187+
187188 @inlinable
188189 public var endIndex : Index {
189190 Index ( first: base. endIndex, second: base. endIndex)
@@ -207,20 +208,23 @@ extension AdjacentPairsCollection: Collection {
207208 public func index( _ i: Index , offsetBy distance: Int ) -> Index {
208209 guard distance != 0 else { return i }
209210
210- guard let result = distance > 0
211- ? offsetForward ( i, by: distance, limitedBy: endIndex)
212- : offsetBackward ( i, by: - distance, limitedBy: startIndex)
211+ guard
212+ let result = distance > 0
213+ ? offsetForward ( i, by: distance, limitedBy: endIndex)
214+ : offsetBackward ( i, by: - distance, limitedBy: startIndex)
213215 else { fatalError ( " Index out of bounds " ) }
214216 return result
215217 }
216218
217219 @inlinable
218220 public func index(
219- _ i: Index , offsetBy distance: Int , limitedBy limit: Index
221+ _ i: Index ,
222+ offsetBy distance: Int ,
223+ limitedBy limit: Index
220224 ) -> Index ? {
221225 guard distance != 0 else { return i }
222226 guard limit != i else { return nil }
223-
227+
224228 if distance > 0 {
225229 let limit = limit > i ? limit : endIndex
226230 return offsetForward ( i, by: distance, limitedBy: limit)
@@ -229,38 +233,48 @@ extension AdjacentPairsCollection: Collection {
229233 return offsetBackward ( i, by: - distance, limitedBy: limit)
230234 }
231235 }
232-
236+
233237 @inlinable
234238 internal func offsetForward(
235- _ i: Index , by distance: Int , limitedBy limit: Index
239+ _ i: Index ,
240+ by distance: Int ,
241+ limitedBy limit: Index
236242 ) -> Index ? {
237243 assert ( distance > 0 )
238244 assert ( limit > i)
239-
240- guard let newFirst = base. index ( i. second, offsetBy: distance - 1 , limitedBy: limit. first) ,
241- newFirst != base. endIndex
245+
246+ let newFirst = base. index (
247+ i. second,
248+ offsetBy: distance - 1 ,
249+ limitedBy: limit. first)
250+ guard let newFirst, newFirst != base. endIndex
242251 else { return nil }
252+
243253 let newSecond = base. index ( after: newFirst)
244-
254+
245255 precondition ( newSecond <= base. endIndex, " Can't advance beyond endIndex " )
246256 return newSecond == base. endIndex
247257 ? endIndex
248258 : Index ( first: newFirst, second: newSecond)
249259 }
250-
260+
251261 @inlinable
252262 internal func offsetBackward(
253- _ i: Index , by distance: Int , limitedBy limit: Index
263+ _ i: Index ,
264+ by distance: Int ,
265+ limitedBy limit: Index
254266 ) -> Index ? {
255267 assert ( distance > 0 )
256268 assert ( limit < i)
257-
269+
258270 let offset = i == endIndex ? 0 : 1
259- guard let newSecond = base. index (
271+ let newSecond = base. index (
260272 i. first,
261273 offsetBy: - ( distance - offset) ,
262274 limitedBy: limit. second)
275+ guard let newSecond
263276 else { return nil }
277+
264278 let newFirst = base. index ( newSecond, offsetBy: - 1 )
265279 precondition ( newFirst >= base. startIndex, " Can't move before startIndex " )
266280 return Index ( first: newFirst, second: newSecond)
@@ -282,12 +296,12 @@ extension AdjacentPairsCollection: Collection {
282296}
283297
284298extension AdjacentPairsCollection : BidirectionalCollection
285- where Base: BidirectionalCollection
286- {
299+ where Base: BidirectionalCollection {
287300 @inlinable
288301 public func index( before i: Index ) -> Index {
289302 precondition ( i != startIndex, " Can't offset before startIndex " )
290- let second = i == endIndex
303+ let second =
304+ i == endIndex
291305 ? base. index ( before: base. endIndex)
292306 : i. first
293307 let first = base. index ( before: second)
@@ -296,10 +310,10 @@ extension AdjacentPairsCollection: BidirectionalCollection
296310}
297311
298312extension AdjacentPairsCollection : RandomAccessCollection
299- where Base: RandomAccessCollection { }
313+ where Base: RandomAccessCollection { }
300314
301315extension AdjacentPairsCollection : LazySequenceProtocol , LazyCollectionProtocol
302- where Base: LazySequenceProtocol { }
316+ where Base: LazySequenceProtocol { }
303317
304318extension AdjacentPairsCollection . Index : Hashable where Base. Index: Hashable {
305319 @inlinable
0 commit comments