File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -272,12 +272,12 @@ extension LinkedList {
272
272
}
273
273
}
274
274
275
- // MARK: - Extension to enable initialization from an Array
275
+ // MARK: - Extension to enable initialization from a Sequence
276
276
extension LinkedList {
277
- convenience init ( array : Array < T > ) {
277
+ convenience init < S > ( _ sequence : S ) where S : Sequence , S . Element == T {
278
278
self . init ( )
279
279
280
- array . forEach { append ( $0) }
280
+ sequence . forEach { append ( $0) }
281
281
}
282
282
}
283
283
Original file line number Diff line number Diff line change @@ -266,12 +266,12 @@ extension LinkedList {
266
266
}
267
267
}
268
268
269
- // MARK: - Extension to enable initialization from an Array
269
+ // MARK: - Extension to enable initialization from a Sequence
270
270
extension LinkedList {
271
- convenience init ( array : Array < T > ) {
271
+ convenience init < S > ( _ sequence : S ) where S : Sequence , S . Element == T {
272
272
self . init ( )
273
273
274
- array . forEach { append ( $0) }
274
+ sequence . forEach { append ( $0) }
275
275
}
276
276
}
277
277
Original file line number Diff line number Diff line change @@ -307,6 +307,17 @@ class LinkedListTest: XCTestCase {
307
307
XCTAssertEqual ( nodeCount, list. count)
308
308
}
309
309
310
+ func testSequenceInitTypeInfer( ) {
311
+ let arrayInitInfer = LinkedList ( [ 1.0 , 2.0 , 3.0 ] )
312
+
313
+ XCTAssertEqual ( arrayInitInfer. count, 3 )
314
+ XCTAssertEqual ( arrayInitInfer. head? . value, 1.0 )
315
+ XCTAssertEqual ( arrayInitInfer. last? . value, 3.0 )
316
+ XCTAssertEqual ( arrayInitInfer [ 1 ] , 2.0 )
317
+ XCTAssertEqual ( arrayInitInfer. removeLast ( ) , 3.0 )
318
+ XCTAssertEqual ( arrayInitInfer. count, 2 )
319
+ }
320
+
310
321
func testArrayLiteralInitTypeInfer( ) {
311
322
let arrayLiteralInitInfer : LinkedList = [ 1.0 , 2.0 , 3.0 ]
312
323
You can’t perform that action at this time.
0 commit comments