From 18c4cd859859396d22f3c54882ff99218fefbba2 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 12 Apr 2019 22:24:32 -0400 Subject: [PATCH 1/4] Replace assert(false) with fatalError() --- SwiftGit2/CommitIterator.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftGit2/CommitIterator.swift b/SwiftGit2/CommitIterator.swift index 0b27399..e8f34ed 100644 --- a/SwiftGit2/CommitIterator.swift +++ b/SwiftGit2/CommitIterator.swift @@ -97,8 +97,8 @@ public class CommitIterator: IteratorProtocol, Sequence { } } - private func notImplemented(functionName: Any) { - assert(false, "CommitIterator does not implement \(functionName)") + private func notImplemented(functionName: Any, file: StaticString = #file, line: UInt = #line) { + fatalError("CommitIterator does not implement \(functionName)", file: file, line: line) } private init(repo: Repository) { self.repo = repo From d878fea6963a81cf60dd39b7b248f4b97d784c18 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 12 Apr 2019 22:27:12 -0400 Subject: [PATCH 2/4] Return Never from notImplemented() to avoid needing dummy return values --- SwiftGit2/CommitIterator.swift | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/SwiftGit2/CommitIterator.swift b/SwiftGit2/CommitIterator.swift index e8f34ed..d28a647 100644 --- a/SwiftGit2/CommitIterator.swift +++ b/SwiftGit2/CommitIterator.swift @@ -97,46 +97,36 @@ public class CommitIterator: IteratorProtocol, Sequence { } } - private func notImplemented(functionName: Any, file: StaticString = #file, line: UInt = #line) { + private func notImplemented(functionName: Any, file: StaticString = #file, line: UInt = #line) -> Never { fatalError("CommitIterator does not implement \(functionName)", file: file, line: line) } - private init(repo: Repository) { - self.repo = repo - } public func dropFirst(_ num: Int) -> AnySequence { notImplemented(functionName: self.dropFirst) - return AnySequence { return CommitIterator(repo: self.repo) } } public func dropLast(_ num: Int) -> AnySequence { notImplemented(functionName: self.dropLast) - return AnySequence { return CommitIterator(repo: self.repo) } } public func drop(while predicate: (Result) throws -> Bool) rethrows -> AnySequence { notImplemented(functionName: self.drop) - return AnySequence { return CommitIterator(repo: self.repo) } } public func prefix(_ maxLength: Int) -> AnySequence { notImplemented(functionName: "prefix(_ maxLength:") - return AnySequence { return CommitIterator(repo: self.repo) } } public func prefix(while predicate: (Result) throws -> Bool) rethrows -> AnySequence { notImplemented(functionName: "prefix(with predicate:") - return AnySequence { return CommitIterator(repo: self.repo) } } public func suffix(_ maxLength: Int) -> AnySequence { notImplemented(functionName: self.suffix) - return AnySequence { return CommitIterator(repo: self.repo) } } public func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator isSeparator: (Result) throws -> Bool) rethrows -> [AnySequence] { notImplemented(functionName: self.split) - return [AnySequence { return CommitIterator(repo: self.repo) }] } } From 3db2f74ac4dae23ef3b71e276a44576c07dfdb8c Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 12 Apr 2019 22:57:22 -0400 Subject: [PATCH 3/4] Delete unimplemented Sequence methods from CommitIterator Implementing these methods is not required to conform to the Sequence protocol, and default implementations are available via standard library extensions on Sequence. --- SwiftGit2/CommitIterator.swift | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/SwiftGit2/CommitIterator.swift b/SwiftGit2/CommitIterator.swift index d28a647..5e2c192 100644 --- a/SwiftGit2/CommitIterator.swift +++ b/SwiftGit2/CommitIterator.swift @@ -96,37 +96,4 @@ public class CommitIterator: IteratorProtocol, Sequence { try body(item) } } - - private func notImplemented(functionName: Any, file: StaticString = #file, line: UInt = #line) -> Never { - fatalError("CommitIterator does not implement \(functionName)", file: file, line: line) - } - - public func dropFirst(_ num: Int) -> AnySequence { - notImplemented(functionName: self.dropFirst) - } - - public func dropLast(_ num: Int) -> AnySequence { - notImplemented(functionName: self.dropLast) - } - - public func drop(while predicate: (Result) throws -> Bool) rethrows -> AnySequence { - notImplemented(functionName: self.drop) - } - - public func prefix(_ maxLength: Int) -> AnySequence { - notImplemented(functionName: "prefix(_ maxLength:") - } - - public func prefix(while predicate: (Result) throws -> Bool) rethrows -> AnySequence { - notImplemented(functionName: "prefix(with predicate:") - } - - public func suffix(_ maxLength: Int) -> AnySequence { - notImplemented(functionName: self.suffix) - } - - public func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator isSeparator: (Result) throws -> Bool) rethrows -> [AnySequence] { - notImplemented(functionName: self.split) - } - } From 452979bd64b061efed814df1b787d70b69af233f Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 12 Apr 2019 23:38:42 -0400 Subject: [PATCH 4/4] Delete Sequence methods from CommitIterator Default implementations are available via standard library extensions on Sequence. --- SwiftGit2/CommitIterator.swift | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/SwiftGit2/CommitIterator.swift b/SwiftGit2/CommitIterator.swift index 5e2c192..0974da7 100644 --- a/SwiftGit2/CommitIterator.swift +++ b/SwiftGit2/CommitIterator.swift @@ -67,33 +67,4 @@ public class CommitIterator: IteratorProtocol, Sequence { return result } } - - public func makeIterator() -> CommitIterator { - return self - } - - public private(set) var underestimatedCount: Int = 0 - public func map(_ transform: (Result) throws -> T) rethrows -> [T] { - var new: [T] = [] - for item in self { - new += [try transform(item)] - } - return new - } - - public func filter(_ isIncluded: (Result) throws -> Bool) rethrows -> [Result] { - var new: [Result] = [] - for item in self { - if try isIncluded(item) { - new += [item] - } - } - return new - } - - public func forEach(_ body: (Result) throws -> Void) rethrows { - for item in self { - try body(item) - } - } }