Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Convert to Swift 3 #2

Open
wants to merge 1 commit into
base: swift-2_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Lustre.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -355,6 +356,7 @@
};
DB5BCE741B6207A7009E42A9 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -626,6 +639,7 @@
baseConfigurationReference = DB5BCE3C1B62005E009E42A9 /* Tests.xcconfig */;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -634,6 +648,7 @@
baseConfigurationReference = DB5BCE3C1B62005E009E42A9 /* Tests.xcconfig */;
buildSettings = {
GCC_C_LANGUAGE_STANDARD = gnu99;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Lustre.xcodeproj/xcshareddata/xcschemes/Lustre.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 5 additions & 5 deletions Lustre/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Either: EitherType {
self = .Right(right)
}

public func analysis<Result>(@noescape ifLeft ifLeft: T -> Result, @noescape ifRight: U -> Result) -> Result {
public func analysis<Result>(ifLeft: (T) -> Result, ifRight: (U) -> Result) -> Result {
switch self {
case .Left(let value): return ifLeft(value)
case .Right(let value): return ifRight(value)
Expand All @@ -32,19 +32,19 @@ extension Either: EitherType {

extension EitherType {

public func flatMapLeft<NewLeft>(@noescape transform: LeftType -> Either<NewLeft, RightType>) -> Either<NewLeft, RightType> {
public func flatMapLeft<NewLeft>(_ transform: (LeftType) -> Either<NewLeft, RightType>) -> Either<NewLeft, RightType> {
return analysis(ifLeft: transform, ifRight: Either.Right)
}

public func mapLeft<NewLeft>(@noescape transform: LeftType -> NewLeft) -> Either<NewLeft, RightType> {
public func mapLeft<NewLeft>(_ transform: (LeftType) -> NewLeft) -> Either<NewLeft, RightType> {
return flatMapLeft { .Left(transform($0)) }
}

public func flatMapRight<NewRight>(@noescape transform: RightType -> Either<LeftType, NewRight>) -> Either<LeftType, NewRight> {
public func flatMapRight<NewRight>(_ transform: (RightType) -> Either<LeftType, NewRight>) -> Either<LeftType, NewRight> {
return analysis(ifLeft: Either.Left, ifRight: transform)
}

public func mapRight<NewRight>(@noescape transform: RightType -> NewRight) -> Either<LeftType, NewRight> {
public func mapRight<NewRight>(_ transform: (RightType) -> NewRight) -> Either<LeftType, NewRight> {
return flatMapRight { .Right(transform($0)) }
}

Expand Down
28 changes: 14 additions & 14 deletions Lustre/EitherType+Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -50,48 +50,48 @@ 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 {
self.init(left: failWith())
}
}

public func recover(@autoclosure fallbackValue: () -> RightType) -> RightType {
public func recover(_ fallbackValue: @autoclosure () -> RightType) -> RightType {
return analysis(ifLeft: { _ in fallbackValue() }, ifRight: { $0 })
}

}

public func ??<Either: EitherType where Either.LeftType == ErrorType>(lhs: Either, @autoclosure rhs: () -> Either.RightType) -> Either.RightType {
public func ??<Either: EitherType>(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 ==<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == ErrorType, RightEither.LeftType == ErrorType, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func ==<LeftEither: EitherType, RightEither: EitherType>(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 !=<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == ErrorType, RightEither.LeftType == ErrorType, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func !=<LeftEither: EitherType, RightEither: EitherType>(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType {
return !(lhs == rhs)
}

public func ==<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == ErrorType, RightEither.LeftType == ErrorType, LeftEither.RightType == Void, RightEither.RightType == Void>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func ==<LeftEither: EitherType, RightEither: EitherType>(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 !=<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == ErrorType, RightEither.LeftType == ErrorType, LeftEither.RightType == Void, RightEither.RightType == Void>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func !=<LeftEither: EitherType, RightEither: EitherType>(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Error, RightEither.LeftType == Error, LeftEither.RightType == Void, RightEither.RightType == Void {
return !(lhs == rhs)
}
22 changes: 11 additions & 11 deletions Lustre/EitherType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result>(@noescape ifLeft ifLeft: LeftType -> Result, @noescape ifRight: RightType -> Result) -> Result
func analysis<Result>(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 {
Expand Down Expand Up @@ -76,7 +76,7 @@ extension EitherType where RightType == Void {

extension EitherType {

public func equals<OtherEither: EitherType>(other: OtherEither, @noescape leftEqual: (LeftType, OtherEither.LeftType) -> Bool, @noescape rightEqual: (RightType, OtherEither.RightType) -> Bool) -> Bool {
public func equals<OtherEither: EitherType>(_ 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)
Expand All @@ -90,26 +90,26 @@ extension EitherType {

}

public func ==<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType: Equatable, LeftEither.RightType: Equatable, RightEither.LeftType == LeftEither.LeftType, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func ==<LeftEither: EitherType, RightEither: EitherType>(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 !=<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType: Equatable, LeftEither.RightType: Equatable, RightEither.LeftType == LeftEither.LeftType, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func !=<LeftEither: EitherType, RightEither: EitherType>(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 ==<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == Void, RightEither.LeftType == Void, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func ==<LeftEither: EitherType, RightEither: EitherType>(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 !=<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType == Void, RightEither.LeftType == Void, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func !=<LeftEither: EitherType, RightEither: EitherType>(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType == Void, RightEither.LeftType == Void, LeftEither.RightType: Equatable, RightEither.RightType == LeftEither.RightType {
return !(lhs == rhs)
}

public func ==<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType: Equatable, RightEither.LeftType == LeftEither.LeftType, LeftEither.RightType == Void, RightEither.RightType == Void>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func ==<LeftEither: EitherType, RightEither: EitherType>(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 !=<LeftEither: EitherType, RightEither: EitherType where LeftEither.LeftType: Equatable, RightEither.LeftType == LeftEither.LeftType, LeftEither.RightType == Void, RightEither.RightType == Void>(lhs: LeftEither, rhs: RightEither) -> Bool {
public func !=<LeftEither: EitherType, RightEither: EitherType>(lhs: LeftEither, rhs: RightEither) -> Bool where LeftEither.LeftType: Equatable, RightEither.LeftType == LeftEither.LeftType, LeftEither.RightType == Void, RightEither.RightType == Void {
return !(lhs == rhs)
}
10 changes: 5 additions & 5 deletions Lustre/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result>(@noescape ifLeft ifLeft: Void -> Result, @noescape ifRight: Wrapped -> Result) -> Result {
public func analysis<Result>(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)
}
}

Expand Down
Loading