Skip to content

Commit

Permalink
Update to Swift 5 (#210)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jsbean authored Jun 12, 2019
1 parent d699d35 commit fc7d6a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ os:
language: generic
sudo: required
dist: trusty
osx_image: xcode10
osx_image: xcode10.2
install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
env:
- SWIFT_VERSION=4.2
- SWIFT_VERSION=5.0
script:
- swift package update
- swift test -c release
Expand Down
2 changes: 1 addition & 1 deletion Sources/Algorithms/Combinatorics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension Collection {
extension Sequence {

/// - Returns: `Zip2Sequence` of 2-tuples composed of adjacent values.
public var pairs: Zip2Sequence<Self,SubSequence> {
public var pairs: Zip2Sequence<Self,DropFirstSequence<Self>> {
return zip(self,dropFirst())
}
}
5 changes: 3 additions & 2 deletions Sources/DataStructures/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ public struct Matrix <Element> {
}
}

extension Matrix: CollectionWrapping {
extension Matrix: SequenceWrapping {

// MARK: - CollectionWrapping
// MARK: - SequenceWrapping

/// - returns: Underlying `Collection`.
public var base: [Element] {
return grid
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/DataStructures/Metatype.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Metatype: Hashable {

/// - Returns: A unique hash value for the metatype wrapped-up herein.
@inlinable
public var hashValue: Int {
return ObjectIdentifier(base).hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(base).hashValue)
}
}
35 changes: 0 additions & 35 deletions Sources/DataStructures/NewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,3 @@ extension NewType where Value: Numeric {
}

extension NewType where Value: SignedNumeric { }

extension NewType where Value: Sequence {
public func makeIterator() -> Value.Iterator {
return value.makeIterator()
}
}

extension NewType where Value: Collection {

public typealias Iterator = Value.Iterator

/// Start index.
public var startIndex: Value.Index {
return value.startIndex
}

/// End index.
public var endIndex: Value.Index {
return value.endIndex
}

/// Index after given index `i`.
public func index(after i: Value.Index) -> Value.Index {
return value.index(after: i)
}

public var indices: Value.Indices {
return value.indices
}

/// - returns: Element at the given `index`.
public subscript (index: Value.Index) -> Value.Element {
return value[index]
}
}
25 changes: 8 additions & 17 deletions Sources/DataStructures/Wrapping/SequenceWrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,25 @@
///
/// In the `init` method of the conforming `struct`, set the value of this private `var` with
/// the given `sequence`.
///
/// - TODO: Consider removing `ExpressibleByArrayLiteral` and `init` requirements.
public protocol SequenceWrapping: Sequence, ExpressibleByArrayLiteral {
public protocol SequenceWrapping: Sequence {

// MARK: Associated Types

// MARK: - Instance Properties

/// `AnySequence` wrapper that provides shade for the domain specific implementation.
var sequence: AnySequence<Element> { get }
/// Wrapped `Collection`-conforming type.
associatedtype Base: Sequence

// MARK: - Initializers
// MARK: - Instance Properties

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

extension SequenceWrapping {

// MARK: - Sequence

/// - returns a generator over the elements of this sequence.
public func makeIterator() -> AnyIterator<Element> {

let iterator = sequence.makeIterator()

return AnyIterator {
return iterator.next()
}
public func makeIterator() -> Base.Iterator {
return base.makeIterator()
}
}
12 changes: 0 additions & 12 deletions Tests/DataStructuresTests/NewTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,4 @@ class NewTypeTests: XCTestCase {
let n: SN = 1
let _ = -n
}

func testSequence() {
struct S: NewType, Sequence { let value: [Int] }
let s = S([1,2,3])
let _ = s.map { $0 }
}

func testCollection() {
struct C: NewType, Collection { let value: [Int] }
let c = C([1,2,3])
let _ = c.count
}
}
2 changes: 0 additions & 2 deletions Tests/DataStructuresTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,10 @@ extension MutableGraphTests {

extension NewTypeTests {
static let __allTests = [
("testCollection", testCollection),
("testComparable", testComparable),
("testExpressibleByFloatLiteral", testExpressibleByFloatLiteral),
("testExpressibleByIntegerLiteral", testExpressibleByIntegerLiteral),
("testNumeric", testNumeric),
("testSequence", testSequence),
("testSignedNumeric", testSignedNumeric),
]
}
Expand Down

0 comments on commit fc7d6a9

Please sign in to comment.