diff --git a/Lustre.xcodeproj/project.pbxproj b/Lustre.xcodeproj/project.pbxproj index a558489..2acdd31 100644 --- a/Lustre.xcodeproj/project.pbxproj +++ b/Lustre.xcodeproj/project.pbxproj @@ -338,11 +338,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Zachary Waldowski"; TargetAttributes = { DB5BCDF01B61FE8A009E42A9 = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0800; }; DB5BCE0F1B61FE94009E42A9 = { CreatedOnToolsVersion = 7.0; @@ -355,6 +356,7 @@ }; DB5BCE741B6207A7009E42A9 = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0800; }; }; }; @@ -513,6 +515,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB5BCE391B62001E009E42A9 /* Debug.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; SDKROOT = macosx; }; name = Debug; @@ -521,7 +525,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = DB5BCE3A1B62001E009E42A9 /* Release.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; @@ -535,6 +542,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -547,6 +555,7 @@ DEFINES_MODULE = YES; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -555,6 +564,7 @@ baseConfigurationReference = DB5BCE3B1B62005E009E42A9 /* Lustre.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; ENABLE_BITCODE = YES; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -569,6 +579,7 @@ baseConfigurationReference = DB5BCE3B1B62005E009E42A9 /* Lustre.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; ENABLE_BITCODE = YES; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -601,6 +612,7 @@ baseConfigurationReference = DB5BCE3B1B62005E009E42A9 /* Lustre.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; ENABLE_BITCODE = YES; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -614,6 +626,7 @@ baseConfigurationReference = DB5BCE3B1B62005E009E42A9 /* Lustre.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; ENABLE_BITCODE = YES; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -626,6 +639,7 @@ baseConfigurationReference = DB5BCE3C1B62005E009E42A9 /* Tests.xcconfig */; buildSettings = { GCC_C_LANGUAGE_STANDARD = gnu99; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -634,6 +648,7 @@ baseConfigurationReference = DB5BCE3C1B62005E009E42A9 /* Tests.xcconfig */; buildSettings = { GCC_C_LANGUAGE_STANDARD = gnu99; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Lustre.xcodeproj/xcshareddata/xcschemes/Lustre.xcscheme b/Lustre.xcodeproj/xcshareddata/xcschemes/Lustre.xcscheme index da85474..085d1b2 100644 --- a/Lustre.xcodeproj/xcshareddata/xcschemes/Lustre.xcscheme +++ b/Lustre.xcodeproj/xcshareddata/xcschemes/Lustre.xcscheme @@ -1,6 +1,6 @@ (@noescape ifLeft ifLeft: T -> Result, @noescape ifRight: U -> Result) -> Result { + public func analysis(ifLeft: (T) -> Result, ifRight: (U) -> Result) -> Result { switch self { case .Left(let value): return ifLeft(value) case .Right(let value): return ifRight(value) @@ -32,19 +32,19 @@ extension Either: EitherType { extension EitherType { - public func flatMapLeft(@noescape transform: LeftType -> Either) -> Either { + public func flatMapLeft(_ transform: (LeftType) -> Either) -> Either { return analysis(ifLeft: transform, ifRight: Either.Right) } - public func mapLeft(@noescape transform: LeftType -> NewLeft) -> Either { + public func mapLeft(_ transform: (LeftType) -> NewLeft) -> Either { return flatMapLeft { .Left(transform($0)) } } - public func flatMapRight(@noescape transform: RightType -> Either) -> Either { + public func flatMapRight(_ transform: (RightType) -> Either) -> Either { return analysis(ifLeft: Either.Left, ifRight: transform) } - public func mapRight(@noescape transform: RightType -> NewRight) -> Either { + public func mapRight(_ transform: (RightType) -> NewRight) -> Either { return flatMapRight { .Right(transform($0)) } } diff --git a/Lustre/EitherType+Result.swift b/Lustre/EitherType+Result.swift index bd31c86..4738836 100644 --- a/Lustre/EitherType+Result.swift +++ b/Lustre/EitherType+Result.swift @@ -6,7 +6,7 @@ // Copyright © 2014-2015. Some rights reserved. // -extension EitherType where LeftType == ErrorType { +extension EitherType where LeftType == Error { public var isSuccess: Bool { return isRight @@ -28,9 +28,9 @@ extension EitherType where LeftType == ErrorType { // MARK: Throws compatibility -extension EitherType where LeftType == ErrorType { +extension EitherType where LeftType == Error { - public init(@noescape _ fn: () throws -> RightType) { + public init(_ fn: () throws -> RightType) { do { self.init(right: try fn()) } catch { @@ -40,7 +40,7 @@ extension EitherType where LeftType == ErrorType { public func extract() throws -> RightType { var error: LeftType! - guard let value = analysis(ifLeft: { error = $0; return .None }, ifRight: { $0 }) as RightType? else { + guard let value = analysis(ifLeft: { error = $0; return .none }, ifRight: { $0 }) as RightType? else { throw error } return value @@ -50,9 +50,9 @@ extension EitherType where LeftType == ErrorType { // MARK: Value recovery -extension EitherType where LeftType == ErrorType { +extension EitherType where LeftType == Error { - public init(_ value: RightType?, @autoclosure failWith: () -> LeftType) { + public init(_ value: RightType?, failWith: @autoclosure () -> LeftType) { if let value = value { self.init(right: value) } else { @@ -60,38 +60,38 @@ extension EitherType where LeftType == ErrorType { } } - public func recover(@autoclosure fallbackValue: () -> RightType) -> RightType { + public func recover(_ fallbackValue: @autoclosure () -> RightType) -> RightType { return analysis(ifLeft: { _ in fallbackValue() }, ifRight: { $0 }) } } -public func ??(lhs: Either, @autoclosure rhs: () -> Either.RightType) -> Either.RightType { +public func ??(lhs: Either, rhs: @autoclosure () -> Either.RightType) -> Either.RightType where Either.LeftType == Error { return lhs.recover(rhs()) } // MARK: Result equatability -extension ErrorType { +extension Error { - public func matches(other: ErrorType) -> Bool { + public func matches(_ other: Error) -> Bool { return (self as NSError) == (other as NSError) } } -public func ==(lhs: LeftEither, rhs: RightEither) -> Bool { +public func ==(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType { return lhs.equals(rhs, leftEqual: { $0.matches($1) }, rightEqual: ==) } -public func !=(lhs: LeftEither, rhs: RightEither) -> Bool { +public func !=(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType { return !(lhs == rhs) } -public func ==(lhs: LeftEither, rhs: RightEither) -> Bool { +public func ==(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType == Void, RightEither.RightType == Void { return lhs.equals(rhs, leftEqual: { $0.matches($1) }, rightEqual: { _ in true }) } -public func !=(lhs: LeftEither, rhs: RightEither) -> Bool { +public func !=(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType == Void, RightEither.RightType == Void { return !(lhs == rhs) } diff --git a/Lustre/EitherType.swift b/Lustre/EitherType.swift index beb5947..4e76d03 100644 --- a/Lustre/EitherType.swift +++ b/Lustre/EitherType.swift @@ -7,19 +7,19 @@ // public protocol EitherType: CustomStringConvertible, CustomDebugStringConvertible { - typealias LeftType - typealias RightType + associatedtype LeftType + associatedtype RightType init(left: LeftType) init(right: RightType) - func analysis(@noescape ifLeft ifLeft: LeftType -> Result, @noescape ifRight: RightType -> Result) -> Result + func analysis(ifLeft: (LeftType) -> Result, ifRight: (RightType) -> Result) -> Result } extension EitherType { public var description: String { - return analysis(ifLeft: { String($0) }, ifRight: { String($0) }) + return analysis(ifLeft: { String(describing: $0) }, ifRight: { String(describing: $0) }) } public var debugDescription: String { @@ -76,7 +76,7 @@ extension EitherType where RightType == Void { extension EitherType { - public func equals(other: OtherEither, @noescape leftEqual: (LeftType, OtherEither.LeftType) -> Bool, @noescape rightEqual: (RightType, OtherEither.RightType) -> Bool) -> Bool { + public func equals(_ other: OtherEither, leftEqual: (LeftType, OtherEither.LeftType) -> Bool, rightEqual: (RightType, OtherEither.RightType) -> Bool) -> Bool { return analysis(ifLeft: { lhsLeft in other.analysis(ifLeft: { rhsLeft in leftEqual(lhsLeft, rhsLeft) @@ -90,26 +90,26 @@ extension EitherType { } -public func ==(lhs: LeftEither, rhs: RightEither) -> Bool { +public func ==(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType: Equatable, LeftEither.RightType: Equatable, RightEither.LeftType == LeftEither.LeftType, RightEither.RightType == LeftEither.RightType { return lhs.equals(rhs, leftEqual: ==, rightEqual: ==) } -public func !=(lhs: LeftEither, rhs: RightEither) -> Bool { +public func !=(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType: Equatable, LeftEither.RightType: Equatable, RightEither.LeftType == LeftEither.LeftType, RightEither.RightType == LeftEither.RightType { return !(lhs == rhs) } -public func ==(lhs: LeftEither, rhs: RightEither) -> Bool { +public func ==(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Void, RightEither.LeftType == Void, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType { return lhs.equals(rhs, leftEqual: { _ in true }, rightEqual: ==) } -public func !=(lhs: LeftEither, rhs: RightEither) -> Bool { +public func !=(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Void, RightEither.LeftType == Void, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType { return !(lhs == rhs) } -public func ==(lhs: LeftEither, rhs: RightEither) -> Bool { +public func ==(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType: Equatable, RightEither.LeftType == LeftEither.LeftType, LeftEither.RightType == Void, RightEither.RightType == Void { return lhs.equals(rhs, leftEqual: ==, rightEqual: { _ in true }) } -public func !=(lhs: LeftEither, rhs: RightEither) -> Bool { +public func !=(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType: Equatable, RightEither.LeftType == LeftEither.LeftType, LeftEither.RightType == Void, RightEither.RightType == Void { return !(lhs == rhs) } diff --git a/Lustre/Optional.swift b/Lustre/Optional.swift index 5dbb7e5..c8c6b12 100644 --- a/Lustre/Optional.swift +++ b/Lustre/Optional.swift @@ -9,17 +9,17 @@ extension Optional: EitherType { public init(left: Void) { - self = .None + self = .none } public init(right: Wrapped) { - self = .Some(right) + self = .some(right) } - public func analysis(@noescape ifLeft ifLeft: Void -> Result, @noescape ifRight: Wrapped -> Result) -> Result { + public func analysis(ifLeft: (Void) -> Result, ifRight: (Wrapped) -> Result) -> Result { switch self { - case .None: return ifLeft() - case .Some(let value): return ifRight(value) + case .none: return ifLeft() + case .some(let value): return ifRight(value) } } diff --git a/Lustre/Result.swift b/Lustre/Result.swift index 920c51d..005c009 100644 --- a/Lustre/Result.swift +++ b/Lustre/Result.swift @@ -7,15 +7,15 @@ // public enum Result { - case Failure(ErrorType) - case Success(T) + case failure(Error) + case success(T) - public init(error: ErrorType) { - self = .Failure(error) + public init(error: Error) { + self = .failure(error) } public init(value: T) { - self = .Success(value) + self = .success(value) } } @@ -23,15 +23,15 @@ extension Result: CustomStringConvertible, CustomDebugStringConvertible { public var description: String { switch self { - case .Failure(let error): return String(error) - case .Success(let value): return String(value) + case .failure(let error): return String(describing: error) + case .success(let value): return String(describing: value) } } public var debugDescription: String { switch self { - case .Failure(let error): return "Failure(\(String(reflecting: error)))" - case .Success(let value): return "Success(\(String(reflecting: value)))" + case .failure(let error): return "Failure(\(String(reflecting: error)))" + case .success(let value): return "Success(\(String(reflecting: value)))" } } @@ -39,7 +39,7 @@ extension Result: CustomStringConvertible, CustomDebugStringConvertible { extension Result: EitherType { - public init(left error: ErrorType) { + public init(left error: Error) { self.init(error: error) } @@ -47,31 +47,31 @@ extension Result: EitherType { self.init(value: value) } - public func analysis(@noescape ifLeft ifLeft: ErrorType -> Result, @noescape ifRight: T -> Result) -> Result { + public func analysis(ifLeft: (Error) -> Result, ifRight: (T) -> Result) -> Result { switch self { - case .Failure(let error): return ifLeft(error) - case .Success(let value): return ifRight(value) + case .failure(let error): return ifLeft(error) + case .success(let value): return ifRight(value) } } } -extension EitherType where LeftType == ErrorType { +extension EitherType where LeftType == Error { - public func flatMap(@noescape transform: RightType -> Result) -> Result { - return analysis(ifLeft: Result.Failure, ifRight: transform) + public func flatMap(_ transform: (RightType) -> Result) -> Result { + return analysis(ifLeft: Result.failure, ifRight: transform) } - public func map(@noescape transform: RightType -> Value) -> Result { - return flatMap { .Success(transform($0)) } + public func map(_ transform: (RightType) -> Value) -> Result { + return flatMap { .success(transform($0)) } } - public func recoverWith(@autoclosure fallbackResult: () -> Result) -> Result { - return analysis(ifLeft: { _ in fallbackResult() }, ifRight: Result.Success) + public func recoverWith(_ fallbackResult: @autoclosure () -> Result) -> Result { + return analysis(ifLeft: { _ in fallbackResult() }, ifRight: Result.success) } } -public func ??(lhs: Either, @autoclosure rhs: () -> Result) -> Result { +public func ??(lhs: Either, rhs: @autoclosure () -> Result) -> Result where Either.LeftType == Error { return lhs.recoverWith(rhs()) } diff --git a/Lustre/ResultFlatMap.swift b/Lustre/ResultFlatMap.swift index b09e239..e62face 100755 --- a/Lustre/ResultFlatMap.swift +++ b/Lustre/ResultFlatMap.swift @@ -6,91 +6,91 @@ // Copyright © 2014-2015 Big Nerd Ranch Inc. Licensed under MIT. // -public func flatMapAll(e0: E0, _ e1: E1, @noescape transform: (E0.RightType, E1.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, transform: @escaping (E0.RightType, E1.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error { return e0.flatMap { s0 in e1.flatMap { transform(s0, $0) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, @noescape transform: (E0.RightType, E1.RightType, E2.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, transform: @escaping (E0.RightType, E1.RightType, E2.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2) { transform(s0, $0, $1) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3) { transform(s0, $0, $1, $2) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4) { transform(s0, $0, $1, $2, $3) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5) { transform(s0, $0, $1, $2, $3, $4) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6) { transform(s0, $0, $1, $2, $3, $4, $5) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7) { transform(s0, $0, $1, $2, $3, $4, $5, $6) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error, E14.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) } } } -public func flatMapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, _ e15: E15, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType, E15.RightType) -> Result) -> Result { +public func flatMapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, _ e15: E15, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType, E15.RightType) -> Result) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error, E14.LeftType == Error, E15.LeftType == Error { return e0.flatMap { s0 in flatMapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) } } diff --git a/Lustre/ResultMap.swift b/Lustre/ResultMap.swift index f9b31c6..069bc51 100755 --- a/Lustre/ResultMap.swift +++ b/Lustre/ResultMap.swift @@ -6,92 +6,92 @@ // Copyright © 2014-2015 Big Nerd Ranch Inc. Licensed under MIT. // -public func mapAll(e0: E0, _ e1: E1, @noescape transform: (E0.RightType, E1.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, transform: @escaping (E0.RightType, E1.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error { return e0.flatMap { s0 in e1.map { transform(s0, $0) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, @noescape transform: (E0.RightType, E1.RightType, E2.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, transform: @escaping (E0.RightType, E1.RightType, E2.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2) { transform(s0, $0, $1) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3) { transform(s0, $0, $1, $2) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4) { transform(s0, $0, $1, $2, $3) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5) { transform(s0, $0, $1, $2, $3, $4) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6) { transform(s0, $0, $1, $2, $3, $4, $5) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7) { transform(s0, $0, $1, $2, $3, $4, $5, $6) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error, E14.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) } } } -public func mapAll(e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, _ e15: E15, @noescape transform: (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType, E15.RightType) -> V) -> Result { +public func mapAll(_ e0: E0, _ e1: E1, _ e2: E2, _ e3: E3, _ e4: E4, _ e5: E5, _ e6: E6, _ e7: E7, _ e8: E8, _ e9: E9, _ e10: E10, _ e11: E11, _ e12: E12, _ e13: E13, _ e14: E14, _ e15: E15, transform: @escaping (E0.RightType, E1.RightType, E2.RightType, E3.RightType, E4.RightType, E5.RightType, E6.RightType, E7.RightType, E8.RightType, E9.RightType, E10.RightType, E11.RightType, E12.RightType, E13.RightType, E14.RightType, E15.RightType) -> V) -> Result where E0.LeftType == Error, E1.LeftType == Error, E2.LeftType == Error, E3.LeftType == Error, E4.LeftType == Error, E5.LeftType == Error, E6.LeftType == Error, E7.LeftType == Error, E8.LeftType == Error, E9.LeftType == Error, E10.LeftType == Error, E11.LeftType == Error, E12.LeftType == Error, E13.LeftType == Error, E14.LeftType == Error, E15.LeftType == Error { return e0.flatMap { s0 in mapAll(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15) { transform(s0, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) } } diff --git a/Lustre/SequenceType+Result.swift b/Lustre/SequenceType+Result.swift index 4fb6a33..043d1f8 100644 --- a/Lustre/SequenceType+Result.swift +++ b/Lustre/SequenceType+Result.swift @@ -6,12 +6,12 @@ // Copyright © 2014-2015 Big Nerd Ranch Inc. Licensed under MIT. // -extension SequenceType where Generator.Element: EitherType, Generator.Element.LeftType == ErrorType { +extension Sequence where Iterator.Element: EitherType, Iterator.Element.LeftType == Error { - private typealias Value = Generator.Element.RightType + fileprivate typealias Value = Iterator.Element.RightType - public func partition() -> ([ErrorType], [Value]) { - var lefts = [ErrorType]() + public func partition() -> ([Error], [Value]) { + var lefts = [Error]() var rights = [Value]() for either in self { @@ -28,7 +28,7 @@ extension SequenceType where Generator.Element: EitherType, Generator.Element.Le public func extractAll() throws -> [Value] { var successes = [Value]() - successes.reserveCapacity(underestimateCount()) + successes.reserveCapacity(underestimatedCount) for result in self { successes.append(try result.extract()) @@ -39,19 +39,19 @@ extension SequenceType where Generator.Element: EitherType, Generator.Element.Le public func collectAllSuccesses() -> Result<[Value]> { do { - return .Success(try extractAll()) + return .success(try extractAll()) } catch { - return .Failure(error) + return .failure(error) } } } -extension EitherType where LeftType == ErrorType, RightType: SequenceType { +extension EitherType where LeftType == Error, RightType: Sequence { - private typealias Element = RightType.Generator.Element + fileprivate typealias Element = RightType.Iterator.Element - public func split(@noescape transform: Element -> Result) -> Result<([ErrorType], [NewValue])> { + public func split(_ transform: @escaping (Element) -> Result) -> Result<([Error], [NewValue])> { return map { $0.lazy.map(transform).partition() } diff --git a/LustreTests/CustomResultTests.swift b/LustreTests/CustomResultTests.swift index 4acae67..8e0f4b7 100644 --- a/LustreTests/CustomResultTests.swift +++ b/LustreTests/CustomResultTests.swift @@ -10,21 +10,21 @@ import XCTest @testable import Lustre private enum StringResult: EitherType { - case Failure(ErrorType) - case Success(String) + case failure(Swift.Error) + case success(String) init(right success: String) { - self = .Success(success) + self = .success(success) } - init(left failure: ErrorType) { - self = .Failure(failure) + init(left failure: Swift.Error) { + self = .failure(failure) } - func analysis(@noescape ifLeft ifLeft: ErrorType -> Result, @noescape ifRight: String -> Result) -> Result { + func analysis(ifLeft: (Swift.Error) -> Result, ifRight: (String) -> Result) -> Result { switch self { - case .Failure(let error): return ifLeft(error) - case .Success(let string): return ifRight(string) + case .failure(let error): return ifLeft(error) + case .success(let string): return ifRight(string) } } @@ -33,29 +33,29 @@ private enum StringResult: EitherType { class CustomResultTests: XCTestCase { let aTestValue = "Result" - let aTestError1 = Error.First - let aTestError2 = Error.Second + let aTestError1 = Error.first + let aTestError2 = Error.second - private let aSuccessResult = StringResult.Success("Result") - private let aFailureResult1 = StringResult.Failure(Error.First) - private let aFailureResult2 = StringResult.Failure(Error.Second) + fileprivate let aSuccessResult = StringResult.success("Result") + fileprivate let aFailureResult1 = StringResult.failure(Error.first) + fileprivate let aFailureResult2 = StringResult.failure(Error.second) func testSuccessExtract() { assertNoThrow(aSuccessResult.extract, aTestValue) } func testFailureExtract() { - assertThrows(aFailureResult1.extract, Error.First) - assertThrows(aFailureResult2.extract, Error.Second) + assertThrows(aFailureResult1.extract, Error.first) + assertThrows(aFailureResult2.extract, Error.second) } func testDescriptionSuccess() { - XCTAssertEqual(String(aSuccessResult), String(aTestValue)) + XCTAssertEqual(String(describing: aSuccessResult), String(aTestValue)) } func testDescriptionFailure() { - XCTAssertEqual(String(aFailureResult1), "First") - XCTAssertEqual(String(aFailureResult2), "Second") + XCTAssertEqual(String(describing: aFailureResult1), "first") + XCTAssertEqual(String(describing: aFailureResult2), "second") } func testDebugDescriptionSuccess() { @@ -65,7 +65,7 @@ class CustomResultTests: XCTestCase { func testDebugDescriptionFailure() { let debugDescription1 = String(reflecting: aFailureResult1) XCTAssert(debugDescription1.hasPrefix("Left(")) - XCTAssert(debugDescription1.hasSuffix("Error.First)")) + XCTAssert(debugDescription1.hasSuffix("Error.first)")) } func testIsSuccessGetter() { @@ -102,7 +102,7 @@ class CustomResultTests: XCTestCase { } func testCoalesceFailure() { - let result = StringResult(left: Error.Second) + let result = StringResult(left: Error.second) XCTAssertEqual(result ?? "43", "43") } @@ -118,7 +118,7 @@ class CustomResultTests: XCTestCase { XCTAssert(aFailureResult1 != Result(error: aTestError2)) } - private func countCharacters(string: String) -> Int { + fileprivate func countCharacters(_ string: String) -> Int { return string.characters.count } @@ -130,12 +130,12 @@ class CustomResultTests: XCTestCase { assertFailure(aFailureResult1.map(countCharacters), aTestError1) } - private func doubleSuccess(x: String) -> Result { - return .Success(x + x) + fileprivate func doubleSuccess(_ x: String) -> Result { + return .success(x + x) } - private func doubleFailure(x: String) -> Result { - return .Failure(aTestError1) + fileprivate func doubleFailure(_ x: String) -> Result { + return .failure(aTestError1) } func testFlatMapSuccessSuccess() { diff --git a/LustreTests/EitherTests.swift b/LustreTests/EitherTests.swift index 6f0d3a0..d8d85c2 100644 --- a/LustreTests/EitherTests.swift +++ b/LustreTests/EitherTests.swift @@ -15,17 +15,17 @@ class EitherTests: XCTestCase { let aLeftValue1 = -1 let aLeftValue2 = 42 - private let aRightEither1 = Either(right: "words") - private let aLeftEither1 = Either(left: -1) - private let aLeftEither2 = Either(left: 42) + fileprivate let aRightEither1 = Either(right: "words") + fileprivate let aLeftEither1 = Either(left: -1) + fileprivate let aLeftEither2 = Either(left: 42) func testDescriptionRight() { - XCTAssertEqual(String(aRightEither1), aRightValue) + XCTAssertEqual(String(describing: aRightEither1), aRightValue) } func testDescriptionFailure() { - XCTAssertEqual(String(aLeftEither1), String(aLeftValue1)) - XCTAssertEqual(String(aLeftEither2), String(aLeftValue2)) + XCTAssertEqual(String(describing: aLeftEither1), String(aLeftValue1)) + XCTAssertEqual(String(describing: aLeftEither2), String(aLeftValue2)) } func testDebugDescriptionSuccess() { @@ -81,7 +81,7 @@ class EitherTests: XCTestCase { XCTAssert(aLeftEither1 != aLeftEither2) } - private func countCharacters(string: String) -> Int { + fileprivate func countCharacters(_ string: String) -> Int { return string.characters.count } @@ -113,11 +113,11 @@ class EitherTests: XCTestCase { XCTAssert(y.right == nil) } - func doubleLeft(x: Int) -> Either { + func doubleLeft(_ x: Int) -> Either { return Either(left: x * 2) } - func doubleRight(x: String) -> Either { + func doubleRight(_ x: String) -> Either { return Either(right: x + x) } diff --git a/LustreTests/Fixtures.swift b/LustreTests/Fixtures.swift index 58867cd..14ceea9 100644 --- a/LustreTests/Fixtures.swift +++ b/LustreTests/Fixtures.swift @@ -9,27 +9,27 @@ import XCTest import Lustre -enum Error: ErrorType { - case First - case Second - case Third +enum Error: Swift.Error { + case first + case second + case third } -func assertErrorMatches(@autoclosure expression1: () -> ErrorType, @autoclosure _ expression2: () -> ErrorType, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertErrorMatches(_ expression1: @autoclosure () -> Swift.Error, _ expression2: @autoclosure () -> Swift.Error, _ message: String = "", file: StaticString = #file, line: UInt = #line) { XCTAssert(expression1().matches(expression2()), message, file: file, line: line) } // MARK: Throwing assertions -func assertThrows(@noescape fn: () throws -> T, @autoclosure _ getError: () -> ErrorType, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertThrows(_ fn: () throws -> T, _ getError: @autoclosure () -> Swift.Error, _ message: String = "", file: StaticString = #file, line: UInt = #line) { do { _ = try fn() } catch { - assertErrorMatches(error, getError(), "Unexpected error in method failure, threw \(error)", file: file, line: line) + assertErrorMatches(error as! Error, getError(), "Unexpected error in method failure, threw \(error)", file: file, line: line) } } -func assertNoThrow(@noescape expression: () throws -> T, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__, @noescape assertions: T -> ()) { +func assertNoThrow(_ expression: () throws -> T, _ message: String = "", file: StaticString = #file, line: UInt = #line, assertions: (T) -> ()) { do { assertions(try expression()) } catch { @@ -37,17 +37,17 @@ func assertNoThrow(@noescape expression: () throws -> T, _ message: String = } } -func assertNoThrow(file: String = __FILE__, line: UInt = __LINE__, @noescape void fn: () throws -> Void) { +func assertNoThrow(_ file: StaticString = #file, line: UInt = #line, void fn: () throws -> Void) { assertNoThrow(fn, file: file, line: line) { _ in } } -func assertNoThrow(@noescape expression: () throws -> T, @autoclosure _ getValue: () -> T?, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertNoThrow(_ expression: () throws -> T, _ getValue: @autoclosure () -> T?, _ message: String = "", file: StaticString = #file, line: UInt = #line) { assertNoThrow(expression, message, file: file, line: line) { (value: T) in XCTAssertEqual(value, getValue()) } } -func assertNoThrow(@noescape expression: () throws -> [T], @autoclosure _ getValue: () -> [T], _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertNoThrow(_ expression: () throws -> [T], _ getValue: @autoclosure () -> [T], _ message: String = "", file: StaticString = #file, line: UInt = #line) { assertNoThrow(expression, message, file: file, line: line) { XCTAssertEqual($0, getValue()) } @@ -55,11 +55,11 @@ func assertNoThrow(@noescape expression: () throws -> [T], @autocl // MARK: Either assertions -func assertFailure(@autoclosure expression1: () -> Either, @autoclosure _ expression2: () -> ErrorType, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertFailure(_ expression1: @autoclosure () -> Either, _ expression2: @autoclosure () -> Swift.Error, _ message: String = "", file: StaticString = #file, line: UInt = #line) where Either.LeftType == Swift.Error { assertThrows(expression1().extract, expression2(), message, file: file, line: line) } -func assertSuccess(@autoclosure expression1: () -> Either, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__, @noescape assertions: Either.RightType -> ()) { +func assertSuccess(_ expression1: @autoclosure () -> Either, _ message: String = "", file: StaticString = #file, line: UInt = #line, assertions: (Either.RightType) -> ()) where Either.LeftType == Swift.Error { do { assertions(try expression1().extract()) } catch { @@ -67,13 +67,13 @@ func assertSuccess(@autoc } } -func assertSuccess(@autoclosure expression1: () -> Either, @autoclosure _ expression2: () -> Either.RightType, _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertSuccess(_ expression1: @autoclosure () -> Either, _ expression2: @autoclosure () -> Either.RightType, _ message: String = "", file: StaticString = #file, line: UInt = #line) where Either.LeftType == Swift.Error, Either.RightType: Equatable { assertSuccess(expression1, message, file: file, line: line) { XCTAssertEqual($0, expression2(), message, file: file, line: line) } } -func assertSuccess(@autoclosure expression1: () -> Either, @autoclosure _ expression2: () -> [T], _ message: String = "", file: String = __FILE__, line: UInt = __LINE__) { +func assertSuccess(_ expression1: @autoclosure () -> Either, _ expression2: @autoclosure () -> [T], _ message: String = "", file: StaticString = #file, line: UInt = #line) where Either.LeftType == Swift.Error, Either.RightType == [T] { assertSuccess(expression1, message, file: file, line: line) { XCTAssertEqual($0, expression2(), message, file: file, line: line) } diff --git a/LustreTests/MapAllTests.swift b/LustreTests/MapAllTests.swift index db81fc1..96be590 100644 --- a/LustreTests/MapAllTests.swift +++ b/LustreTests/MapAllTests.swift @@ -11,20 +11,20 @@ import XCTest class MapAllTests: XCTestCase { - private let aValue = 42 - private let anError = Error.First + fileprivate let aValue = 42 + fileprivate let anError = Error.first - private let aSuccessResult = Result.Success(42) - private let aFailureResult = Result.Failure(Error.First) + fileprivate let aSuccessResult = Result.success(42) + fileprivate let aFailureResult = Result.failure(Error.first) - private func makeSuccess(i: Int) -> Result { + fileprivate func makeSuccess(_ i: Int) -> Result { return aSuccessResult.map { $0 + i } } - private struct IncrediblyContrived: Equatable { + fileprivate struct IncrediblyContrived: Equatable { - static func create(first: Int, second: Int, third: Int, fourth: Int, fifth: Int, sixth: Int, seventh: Int, eighth: Int, ninth: Int, tenth: Int, eleventh: Int, twelfth: Int, thirteenth: Int, fourteenth: Int, fifteenth: Int, sixteenth: Int) -> Result { - return Result.Success(IncrediblyContrived(first: first, second: second, third: third, fourth: fourth, fifth: fifth, sixth: sixth, seventh: seventh, eighth: eighth, ninth: ninth, tenth: tenth, eleventh: eleventh, twelfth: twelfth, thirteenth: thirteenth, fourteenth: fourteenth, fifteenth: fifteenth, sixteenth: sixteenth)) + static func create(_ first: Int, second: Int, third: Int, fourth: Int, fifth: Int, sixth: Int, seventh: Int, eighth: Int, ninth: Int, tenth: Int, eleventh: Int, twelfth: Int, thirteenth: Int, fourteenth: Int, fifteenth: Int, sixteenth: Int) -> Result { + return Result.success(IncrediblyContrived(first: first, second: second, third: third, fourth: fourth, fifth: fifth, sixth: sixth, seventh: seventh, eighth: eighth, ninth: ninth, tenth: tenth, eleventh: eleventh, twelfth: twelfth, thirteenth: thirteenth, fourteenth: fourteenth, fifteenth: fifteenth, sixteenth: sixteenth)) } let first : Int @@ -45,7 +45,7 @@ class MapAllTests: XCTestCase { let sixteenth : Int } - private let aComposite = IncrediblyContrived(first: 42, second: 43, third: 44, fourth: 45, fifth: 46, sixth: 47, seventh: 48, eighth: 49, ninth: 50, tenth: 51, eleventh: 52, twelfth: 53, thirteenth: 54, fourteenth: 55, fifteenth: 56, sixteenth: 57) + fileprivate let aComposite = IncrediblyContrived(first: 42, second: 43, third: 44, fourth: 45, fifth: 46, sixth: 47, seventh: 48, eighth: 49, ninth: 50, tenth: 51, eleventh: 52, twelfth: 53, thirteenth: 54, fourteenth: 55, fifteenth: 56, sixteenth: 57) func testMapSuccess() { diff --git a/LustreTests/OptionalTests.swift b/LustreTests/OptionalTests.swift index db914c1..f4f902a 100644 --- a/LustreTests/OptionalTests.swift +++ b/LustreTests/OptionalTests.swift @@ -11,10 +11,10 @@ import XCTest class OptionalTests: XCTestCase { - private let aValue = 42 + fileprivate let aValue = 42 - private let aSuccessResult = Either(right: 42) - private var aFailureResult = Either() + fileprivate let aSuccessResult = Either(right: 42) + fileprivate var aFailureResult = Either() func testEqualityOptional() { XCTAssert(aSuccessResult == Optional(right: aValue)) diff --git a/LustreTests/ResultCollectionTests.swift b/LustreTests/ResultCollectionTests.swift index 4a6e782..3191b82 100644 --- a/LustreTests/ResultCollectionTests.swift +++ b/LustreTests/ResultCollectionTests.swift @@ -11,14 +11,14 @@ import XCTest class ResultCollectionTests: XCTestCase { - private let testWithFailure = [ Result(value: -1), Result(value: 0), Result(value: 1), Result(error: Error.First) ] as [Result] - private let testAllSuccesses = [ Result(value: -1), Result(value: 0), Result(value: 1), Result(value: 2) ] as [Result] + fileprivate let testWithFailure = [ Result(value: -1), Result(value: 0), Result(value: 1), Result(error: Error.first) ] as [Result] + fileprivate let testAllSuccesses = [ Result(value: -1), Result(value: 0), Result(value: 1), Result(value: 2) ] as [Result] func testPartition() { let (failures, successes) = testWithFailure.partition() XCTAssertEqual(Set(successes), [ -1, 0, 1 ]) - XCTAssert(failures.elementsEqual(CollectionOfOne(Error.First), isEquivalent: { + XCTAssert(failures.elementsEqual(CollectionOfOne(Error.first), by: { $0.matches($1) })) } @@ -32,7 +32,7 @@ class ResultCollectionTests: XCTestCase { } func testCollectFailure() { - assertFailure(testWithFailure.collectAllSuccesses(), Error.First) + assertFailure(testWithFailure.collectAllSuccesses(), Error.first) } func testSplit() { @@ -41,7 +41,7 @@ class ResultCollectionTests: XCTestCase { if number >= 0 { return Result(value: number * 2) } - return Result(error: Error.First) + return Result(error: Error.first) } assertSuccess(splitResult) { diff --git a/LustreTests/ResultTests.swift b/LustreTests/ResultTests.swift index d4b208c..e5ff869 100644 --- a/LustreTests/ResultTests.swift +++ b/LustreTests/ResultTests.swift @@ -12,29 +12,29 @@ import XCTest class ResultTests: XCTestCase { let aTestValue = 42 - let aTestError1 = Error.First - let aTestError2 = Error.Second + let aTestError1 = Error.first + let aTestError2 = Error.second - private var aSuccessResult = Result(value: 42) - private var aFailureResult1 = Result(error: Error.First) - private var aFailureResult2 = Result(error: Error.Second) + fileprivate var aSuccessResult = Result(value: 42) + fileprivate var aFailureResult1 = Result(error: Error.first) + fileprivate var aFailureResult2 = Result(error: Error.second) func testSuccessExtract() { assertNoThrow(aSuccessResult.extract, aTestValue) } func testFailureExtract() { - assertThrows(aFailureResult1.extract, Error.First) - assertThrows(aFailureResult2.extract, Error.Second) + assertThrows(aFailureResult1.extract, Error.first) + assertThrows(aFailureResult2.extract, Error.second) } func testDescriptionSuccess() { - XCTAssertEqual(String(aSuccessResult), String(aTestValue)) + XCTAssertEqual(String(describing: aSuccessResult), String(aTestValue)) } func testDescriptionFailure() { - XCTAssertEqual(String(aFailureResult1), "First") - XCTAssertEqual(String(aFailureResult2), "Second") + XCTAssertEqual(String(describing: aFailureResult1), "first") + XCTAssertEqual(String(describing: aFailureResult2), "second") } func testDebugDescriptionSuccess() { @@ -44,7 +44,7 @@ class ResultTests: XCTestCase { func testDebugDescriptionFailure() { let debugDescription1 = String(reflecting: aFailureResult1) XCTAssert(debugDescription1.hasPrefix("Failure(")) - XCTAssert(debugDescription1.hasSuffix("Error.First)")) + XCTAssert(debugDescription1.hasSuffix("Error.first)")) } func testSuccessGetter() { @@ -124,14 +124,14 @@ class ResultTests: XCTestCase { func testAnyEquals() { typealias Tuple = (Int, String) let tupleSuccess1: Result = Result(value: (42, "test")) - let tupleFailure1: Result = Result(error: Error.First) - let tupleFailure2: Result = Result(error: Error.Second) + let tupleFailure1: Result = Result(error: Error.first) + let tupleFailure2: Result = Result(error: Error.second) - func tuplesEqual(lhs: Tuple, rhs: Tuple) -> Bool { + func tuplesEqual(_ lhs: Tuple, rhs: Tuple) -> Bool { return lhs.0 == rhs.0 && lhs.1 == rhs.1 } - func errorsEqual(lhs: ErrorType, rhs: ErrorType) -> Bool { + func errorsEqual(_ lhs: Swift.Error, rhs: Swift.Error) -> Bool { return lhs.matches(rhs) } @@ -171,10 +171,10 @@ class ResultTests: XCTestCase { func testMapFailureUnaryOperator() { let x = aFailureResult1.map(-) - assertFailure(x, Error.First) + assertFailure(x, Error.first) } - private func countCharacters(string: String) -> Int { + fileprivate func countCharacters(_ string: String) -> Int { return string.characters.count } @@ -190,11 +190,11 @@ class ResultTests: XCTestCase { assertFailure(y, aTestError1) } - func doubleSuccess(x: Int) -> Result { + func doubleSuccess(_ x: Int) -> Result { return Result(value: x * 2) } - func doubleFailure(x: Int) -> Result { + func doubleFailure(_ x: Int) -> Result { return Result(error: aTestError2) } diff --git a/LustreTests/VoidResultTests.swift b/LustreTests/VoidResultTests.swift index 7ac1bf0..bbf1da8 100644 --- a/LustreTests/VoidResultTests.swift +++ b/LustreTests/VoidResultTests.swift @@ -11,29 +11,29 @@ import XCTest class VoidResultTests: XCTestCase { - private let anError1 = Error.First - private let anError2 = Error.Second - private let aSuccessResult1 = Result() - private let aFailureResult1 = Result(error: Error.First) - private let aSuccessResult2 = ContrivedVoidResult() - private let aFailureResult2 = ContrivedVoidResult(left: Error.Second) - - private enum ContrivedVoidResult: EitherType { - case Failure(ErrorType) - case Success + fileprivate let anError1 = Error.first + fileprivate let anError2 = Error.second + fileprivate let aSuccessResult1 = Result() + fileprivate let aFailureResult1 = Result(error: Error.first) + fileprivate let aSuccessResult2 = ContrivedVoidResult() + fileprivate let aFailureResult2 = ContrivedVoidResult(left: Error.second) + + fileprivate enum ContrivedVoidResult: EitherType { + case failure(Swift.Error) + case success - init(left: ErrorType) { - self = .Failure(left) + init(left: Swift.Error) { + self = .failure(left) } init(right: ()) { - self = .Success + self = .success } - func analysis(@noescape ifLeft ifLeft: ErrorType -> Result, @noescape ifRight: Void -> Result) -> Result { + func analysis(ifLeft: (Swift.Error) -> Result, ifRight: (Void) -> Result) -> Result { switch self { - case .Failure(let error): return ifLeft(error) - case .Success: return ifRight() + case .failure(let error): return ifLeft(error) + case .success: return ifRight() } } @@ -45,18 +45,18 @@ class VoidResultTests: XCTestCase { } func testFailureExtract() { - assertThrows(aFailureResult1.extract, Error.First) - assertThrows(aFailureResult2.extract, Error.Second) + assertThrows(aFailureResult1.extract, Error.first) + assertThrows(aFailureResult2.extract, Error.second) } func testDescriptionSuccess() { - XCTAssertEqual(String(aSuccessResult1), "()") - XCTAssertEqual(String(aSuccessResult2), "()") + XCTAssertEqual(String(describing: aSuccessResult1), "()") + XCTAssertEqual(String(describing: aSuccessResult2), "()") } func testDescriptionFailure() { - XCTAssertEqual(String(aFailureResult1), "First") - XCTAssertEqual(String(aFailureResult2), "Second") + XCTAssertEqual(String(describing: aFailureResult1), "first") + XCTAssertEqual(String(describing: aFailureResult2), "second") } func testDebugDescriptionSuccess() { @@ -67,11 +67,11 @@ class VoidResultTests: XCTestCase { func testDebugDescriptionFailure() { let debugDescription1 = String(reflecting: aFailureResult1) XCTAssert(debugDescription1.hasPrefix("Failure(")) - XCTAssert(debugDescription1.hasSuffix("Error.First)")) + XCTAssert(debugDescription1.hasSuffix("Error.first)")) let debugDescription2 = String(reflecting: aFailureResult2) XCTAssert(debugDescription2.hasPrefix("Left(")) - XCTAssert(debugDescription2.hasSuffix("Error.Second)")) + XCTAssert(debugDescription2.hasSuffix("Error.second)")) } func testSuccessGetter() { @@ -143,14 +143,14 @@ class VoidResultTests: XCTestCase { XCTAssert(aSuccessResult2 != aFailureResult2) XCTAssert(aFailureResult1 != aSuccessResult1) XCTAssert(aFailureResult2 != aSuccessResult2) - XCTAssert(aFailureResult1 != Result(error: Error.Second)) + XCTAssert(aFailureResult1 != Result(error: Error.second)) } func testEqualityDifferentTypes() { XCTAssert(aSuccessResult1 == aSuccessResult2) XCTAssertFalse(aSuccessResult1 == aFailureResult2) XCTAssert(aFailureResult1 == ContrivedVoidResult(left: anError1)) - XCTAssertFalse(aFailureResult1 == ContrivedVoidResult(left: Error.Second)) + XCTAssertFalse(aFailureResult1 == ContrivedVoidResult(left: Error.second)) } func testInequalityDifferentTypes() { @@ -158,12 +158,12 @@ class VoidResultTests: XCTestCase { XCTAssert(aFailureResult1 != aFailureResult2) } - private func doubleSuccess() -> Result { + fileprivate func doubleSuccess() -> Result { return Result(value: 42) } - private func doubleFailure() -> Result { - return Result(error: Error.Third) + fileprivate func doubleFailure() -> Result { + return Result(error: Error.third) } func testFlatMapSuccessSuccess() { @@ -176,8 +176,8 @@ class VoidResultTests: XCTestCase { func testFlatMapSuccessFailure() { let x1 = aSuccessResult1.flatMap(doubleFailure) let x2 = aSuccessResult2.flatMap(doubleFailure) - assertErrorMatches(x1.error!, Error.Third) - assertErrorMatches(x2.error!, Error.Third) + assertErrorMatches(x1.error!, Error.third) + assertErrorMatches(x2.error!, Error.third) } func testFlatMapFailureSuccess() { @@ -194,7 +194,7 @@ class VoidResultTests: XCTestCase { assertErrorMatches(x2.error!, anError2) } - private func mappedString() -> String { + fileprivate func mappedString() -> String { return "Test" } @@ -208,10 +208,10 @@ class VoidResultTests: XCTestCase { func testMapFailureNewType() { let result1 = aFailureResult1.map(mappedString) - assertFailure(result1, Error.First) + assertFailure(result1, Error.first) let result2 = aFailureResult2.map(mappedString) - assertFailure(result2, Error.Second) + assertFailure(result2, Error.second) } }