Skip to content

Commit fc7d6a9

Browse files
authored
Update to Swift 5 (#210)
* Remove NewType wrapping Sequences and Collections, use *Wrapping instead * Remove errant x * Update Metatype: Hashable conformance to use Hasher * Update Travis * Try version 5.0
1 parent d699d35 commit fc7d6a9

File tree

8 files changed

+16
-73
lines changed

8 files changed

+16
-73
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ os:
44
language: generic
55
sudo: required
66
dist: trusty
7-
osx_image: xcode10
7+
osx_image: xcode10.2
88
install:
99
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
1010
env:
11-
- SWIFT_VERSION=4.2
11+
- SWIFT_VERSION=5.0
1212
script:
1313
- swift package update
1414
- swift test -c release

Sources/Algorithms/Combinatorics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension Collection {
5757
extension Sequence {
5858

5959
/// - Returns: `Zip2Sequence` of 2-tuples composed of adjacent values.
60-
public var pairs: Zip2Sequence<Self,SubSequence> {
60+
public var pairs: Zip2Sequence<Self,DropFirstSequence<Self>> {
6161
return zip(self,dropFirst())
6262
}
6363
}

Sources/DataStructures/Matrix.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ public struct Matrix <Element> {
109109
}
110110
}
111111

112-
extension Matrix: CollectionWrapping {
112+
extension Matrix: SequenceWrapping {
113113

114-
// MARK: - CollectionWrapping
114+
// MARK: - SequenceWrapping
115115

116+
/// - returns: Underlying `Collection`.
116117
public var base: [Element] {
117118
return grid
118119
}

Sources/DataStructures/Metatype.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension Metatype: Hashable {
4242

4343
/// - Returns: A unique hash value for the metatype wrapped-up herein.
4444
@inlinable
45-
public var hashValue: Int {
46-
return ObjectIdentifier(base).hashValue
45+
public func hash(into hasher: inout Hasher) {
46+
hasher.combine(ObjectIdentifier(base).hashValue)
4747
}
4848
}

Sources/DataStructures/NewType.swift

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,38 +94,3 @@ extension NewType where Value: Numeric {
9494
}
9595

9696
extension NewType where Value: SignedNumeric { }
97-
98-
extension NewType where Value: Sequence {
99-
public func makeIterator() -> Value.Iterator {
100-
return value.makeIterator()
101-
}
102-
}
103-
104-
extension NewType where Value: Collection {
105-
106-
public typealias Iterator = Value.Iterator
107-
108-
/// Start index.
109-
public var startIndex: Value.Index {
110-
return value.startIndex
111-
}
112-
113-
/// End index.
114-
public var endIndex: Value.Index {
115-
return value.endIndex
116-
}
117-
118-
/// Index after given index `i`.
119-
public func index(after i: Value.Index) -> Value.Index {
120-
return value.index(after: i)
121-
}
122-
123-
public var indices: Value.Indices {
124-
return value.indices
125-
}
126-
127-
/// - returns: Element at the given `index`.
128-
public subscript (index: Value.Index) -> Value.Element {
129-
return value[index]
130-
}
131-
}

Sources/DataStructures/Wrapping/SequenceWrapping.swift

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,25 @@
2121
///
2222
/// In the `init` method of the conforming `struct`, set the value of this private `var` with
2323
/// the given `sequence`.
24-
///
25-
/// - TODO: Consider removing `ExpressibleByArrayLiteral` and `init` requirements.
26-
public protocol SequenceWrapping: Sequence, ExpressibleByArrayLiteral {
24+
public protocol SequenceWrapping: Sequence {
2725

2826
// MARK: Associated Types
2927

30-
// MARK: - Instance Properties
31-
32-
/// `AnySequence` wrapper that provides shade for the domain specific implementation.
33-
var sequence: AnySequence<Element> { get }
28+
/// Wrapped `Collection`-conforming type.
29+
associatedtype Base: Sequence
3430

35-
// MARK: - Initializers
31+
// MARK: - Instance Properties
3632

37-
/// Create an `SequenceWrapping` with a `Sequence`.
38-
init <S> (_ sequence: S) where S: Sequence, S.Element == Element
33+
/// Wrapped `Collection`-conforming type.
34+
var base: Base { get }
3935
}
4036

4137
extension SequenceWrapping {
4238

4339
// MARK: - Sequence
4440

4541
/// - returns a generator over the elements of this sequence.
46-
public func makeIterator() -> AnyIterator<Element> {
47-
48-
let iterator = sequence.makeIterator()
49-
50-
return AnyIterator {
51-
return iterator.next()
52-
}
42+
public func makeIterator() -> Base.Iterator {
43+
return base.makeIterator()
5344
}
5445
}

Tests/DataStructuresTests/NewTypeTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,4 @@ class NewTypeTests: XCTestCase {
4242
let n: SN = 1
4343
let _ = -n
4444
}
45-
46-
func testSequence() {
47-
struct S: NewType, Sequence { let value: [Int] }
48-
let s = S([1,2,3])
49-
let _ = s.map { $0 }
50-
}
51-
52-
func testCollection() {
53-
struct C: NewType, Collection { let value: [Int] }
54-
let c = C([1,2,3])
55-
let _ = c.count
56-
}
5745
}

Tests/DataStructuresTests/XCTestManifests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ extension MutableGraphTests {
277277

278278
extension NewTypeTests {
279279
static let __allTests = [
280-
("testCollection", testCollection),
281280
("testComparable", testComparable),
282281
("testExpressibleByFloatLiteral", testExpressibleByFloatLiteral),
283282
("testExpressibleByIntegerLiteral", testExpressibleByIntegerLiteral),
284283
("testNumeric", testNumeric),
285-
("testSequence", testSequence),
286284
("testSignedNumeric", testSignedNumeric),
287285
]
288286
}

0 commit comments

Comments
 (0)