Skip to content

Commit

Permalink
Merge pull request #178 from jameshurst/xcode8beta4
Browse files Browse the repository at this point in the history
Changes for Xcode 8 beta 4
  • Loading branch information
mdiep authored Aug 6, 2016
2 parents 08d1f80 + 908a267 commit 03eb2c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0-PREVIEW-2
3.0-PREVIEW-4
10 changes: 5 additions & 5 deletions Result/Result.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015 Rob Rix. All rights reserved.

/// An enum representing either a failure with an explanatory error, or a success with a result value.
public enum Result<T, Error: ErrorProtocol>: ResultProtocol, CustomStringConvertible, CustomDebugStringConvertible {
public enum Result<T, Error: Swift.Error>: ResultProtocol, CustomStringConvertible, CustomDebugStringConvertible {
case success(T)
case failure(Error)

Expand Down Expand Up @@ -157,8 +157,8 @@ public func `try`(_ function: String = #function, file: String = #file, line: In
// MARK: - ErrorProtocolConvertible conformance

extension NSError: ErrorProtocolConvertible {
public static func error(from error: ErrorProtocol) -> Self {
func cast<T: NSError>(_ error: ErrorProtocol) -> T {
public static func error(from error: Swift.Error) -> Self {
func cast<T: NSError>(_ error: Swift.Error) -> T {
return error as! T
}

Expand All @@ -173,7 +173,7 @@ extension NSError: ErrorProtocolConvertible {
/// This can be used to describe `Result`s where failures will never
/// be generated. For example, `Result<Int, NoError>` describes a result that
/// contains an `Int`eger and is guaranteed never to be a `Failure`.
public enum NoError: ErrorProtocol { }
public enum NoError: Swift.Error { }

// MARK: - migration support
extension Result {
Expand All @@ -190,7 +190,7 @@ extension Result {

extension NSError {
@available(*, unavailable, renamed: "error(from:)")
public static func errorFromErrorType(_ error: ErrorProtocol) -> Self {
public static func errorFromErrorType(_ error: Swift.Error) -> Self {
fatalError()
}
}
Expand Down
14 changes: 7 additions & 7 deletions Result/ResultProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// A type that can represent either failure with an error or success with a result value.
public protocol ResultProtocol {
associatedtype Value
associatedtype Error: ErrorProtocol
associatedtype Error: Swift.Error

/// Constructs a successful result wrapping a `value`.
init(value: Value)
Expand Down Expand Up @@ -82,8 +82,8 @@ public extension ResultProtocol {
}

/// Protocol used to constrain `tryMap` to `Result`s with compatible `Error`s.
public protocol ErrorProtocolConvertible: ErrorProtocol {
static func error(from error: ErrorProtocol) -> Self
public protocol ErrorProtocolConvertible: Swift.Error {
static func error(from error: Swift.Error) -> Self
}

public extension ResultProtocol where Error: ErrorProtocolConvertible {
Expand Down Expand Up @@ -135,9 +135,9 @@ public func >>- <T: ResultProtocol, U> (result: T, transform: @noescape (T.Value

/// Returns `true` if `left` and `right` are both `Success`es and their values are equal, or if `left` and `right` are both `Failure`s and their errors are equal.
public func == <T: ResultProtocol where T.Value: Equatable, T.Error: Equatable> (left: T, right: T) -> Bool {
if let left = left.value, right = right.value {
if let left = left.value, let right = right.value {
return left == right
} else if let left = left.error, right = right.error {
} else if let left = left.error, let right = right.error {
return left == right
}
return false
Expand All @@ -163,7 +163,7 @@ public func ?? <T: ResultProtocol> (left: T, right: @autoclosure () -> T) -> T {
public typealias ResultType = ResultProtocol

@available(*, unavailable, renamed: "ErrorProtocol")
public typealias ResultErrorType = ErrorProtocol
public typealias ResultErrorType = Swift.Error

@available(*, unavailable, renamed: "ErrorProtocolConvertible")
public typealias ErrorTypeConvertible = ErrorProtocolConvertible
Expand All @@ -177,7 +177,7 @@ extension ResultProtocol {

extension ErrorProtocolConvertible {
@available(*, unavailable, renamed: "error(from:)")
public static func errorFromErrorType(_ error: ErrorProtocol) -> Self {
public static func errorFromErrorType(_ error: Swift.Error) -> Self {
fatalError()
}
}
8 changes: 4 additions & 4 deletions Tests/Result/ResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ final class ResultTests: XCTestCase {
}

func testRecoverProducesRightForLeftFailure() {
struct Error: ErrorProtocol {}
struct Error: Swift.Error {}

let left = Result<String, Error>.failure(Error())
XCTAssertEqual(left.recover("right"), "right")
Expand All @@ -116,7 +116,7 @@ final class ResultTests: XCTestCase {
}

func testRecoverWithProducesRightSuccessForLeftFailureAndRightSuccess() {
struct Error: ErrorProtocol {}
struct Error: Swift.Error {}

let left = Result<String, Error>.failure(Error())
let right = Result<String, Error>.success("right")
Expand All @@ -125,7 +125,7 @@ final class ResultTests: XCTestCase {
}

func testRecoverWithProducesRightFailureForLeftFailureAndRightFailure() {
enum Error: ErrorProtocol { case left, right }
enum Error: Swift.Error { case left, right }

let left = Result<String, Error>.failure(.left)
let right = Result<String, Error>.failure(.right)
Expand Down Expand Up @@ -220,7 +220,7 @@ func attempt<T>(_ value: T, succeed: Bool, error: NSErrorPointer) -> T? {
#endif

func tryIsSuccess(_ text: String?) throws -> String {
guard let text = text where text == "success" else {
guard let text = text, text == "success" else {
throw error
}

Expand Down

0 comments on commit 03eb2c2

Please sign in to comment.