From 4f3767e900aefec65f3739ee3c67c662120af597 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 8 Jun 2015 16:26:38 -0600 Subject: [PATCH 01/48] Update to Swift 2.0 --- Swiftx.xcodeproj/project.pbxproj | 12 ++- .../xcschemes/Swiftx-iOS.xcscheme | 5 +- .../xcshareddata/xcschemes/Swiftx.xcscheme | 5 +- .../xcschemes/SwiftxTests.xcscheme | 5 +- Swiftx/Array.swift | 8 +- Swiftx/Box.swift | 4 +- Swiftx/Either.swift | 8 +- Swiftx/Functions.swift | 16 ++-- Swiftx/Optional.swift | 8 +- Swiftx/Result.swift | 22 ++--- Swiftx/Sections.swift | 96 ++++--------------- SwiftxTests/Info.plist | 2 +- 12 files changed, 77 insertions(+), 114 deletions(-) diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 96444e3..f8bcbd7 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -315,7 +315,8 @@ 84A88C801A70BD71003D53CF /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0620; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = TypeLift; TargetAttributes = { 84A88C881A70BD71003D53CF = { @@ -471,6 +472,7 @@ COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -544,6 +546,7 @@ INFOPLIST_FILE = Swiftx/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.typelift.(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -561,6 +564,7 @@ INFOPLIST_FILE = Swiftx/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.typelift.(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -580,6 +584,7 @@ ); INFOPLIST_FILE = SwiftxTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.maxs.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -594,6 +599,7 @@ ); INFOPLIST_FILE = SwiftxTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.maxs.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -616,6 +622,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.typelift.(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Swiftx; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -636,6 +643,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.typelift.(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = Swiftx; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -661,6 +669,7 @@ INFOPLIST_FILE = SwiftxTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.maxs.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; }; @@ -678,6 +687,7 @@ INFOPLIST_FILE = SwiftxTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "io.maxs.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; diff --git a/Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx-iOS.xcscheme b/Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx-iOS.xcscheme index 23acd5e..c2f7f90 100644 --- a/Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx-iOS.xcscheme +++ b/Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx-iOS.xcscheme @@ -1,6 +1,6 @@ + + + + + + (a: A) -> [A] { +public func pure(a : A) -> [A] { return [a] } /// Fmap | Maps a function over the contents of an array and returns a new array of the resulting /// values. -public func <^> (f: A -> B, a: [A]) -> [B] { +public func <^> (f : A -> B, a: [A]) -> [B] { return a.map(f) } /// Ap | Given an [A -> B] and an [A], returns a [B]. Applies the function at each index in `f` to /// every index in `a` and returns the results in a new array. -public func <*> (f: [(A -> B)], a: [A]) -> [B] { +public func <*> (f : [(A -> B)], a: [A]) -> [B] { var re = [B]() for g in f { for h in a { @@ -31,7 +31,7 @@ public func <*> (f: [(A -> B)], a: [A]) -> [B] { /// Bind | Given an [A], and a function from A -> [B], applies the function `f` to every element in /// [A] and returns the result. -public func >>- (a: [A], f: A -> [B]) -> [B] { +public func >>- (a : [A], f: A -> [B]) -> [B] { var re = [B]() for x in a { re.extend(f(x)) diff --git a/Swiftx/Box.swift b/Swiftx/Box.swift index 1b5b045..6d3fdee 100644 --- a/Swiftx/Box.swift +++ b/Swiftx/Box.swift @@ -30,8 +30,8 @@ public func <^> (f : T -> U, x : Box) -> Box { return x.map(f) } -extension Box : Printable { +extension Box : CustomStringConvertible { public var description: String { - return "Box(\(toString(value)))" + return "Box(\(String(value)))" } } diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 24754bf..93f2595 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -21,7 +21,7 @@ public enum Either { /// Converts a Either to a Result, which is a more specialized type that /// contains an NSError or a value. public func toResult(ev : L -> NSError) -> Result { - return either(onLeft: { e in Result.Error(ev(e)) }, onRight: { v in .Value(Box(v)) }); + return either(onLeft : { e in Result.Error(ev(e)) }, onRight: { v in .Value(Box(v)) }); } @@ -29,7 +29,7 @@ public enum Either { /// and if the Either is Left, returns the value, otherwise maps the function over /// the value in Right and returns that value. public func fold(value : B, f : R -> B) -> B { - return either(onLeft: { _ in value }, onRight: { r in f(r) }); + return either(onLeft : { _ in value }, onRight: { r in f(r) }); } /// Named function for `>>-`. If the Either is Left, simply returns @@ -51,7 +51,7 @@ public enum Either { /// Case analysis for the Either type. If the value is Left(a), apply the first function to a; /// if it is Right(b), apply the second function to b. - public func either(#onLeft : L -> A, onRight : R -> A) -> A { + public func either(onLeft onLeft : L -> A, onRight : R -> A) -> A { switch self { case let Left(e): return onLeft(e.value) @@ -100,7 +100,7 @@ public func <*> (f : Either RB>, a : Either) -> Eithe switch (a, f) { case let (.Left(l), _): return .Left(l) - case let (.Right(r), .Left(m)): + case let (.Right(_), .Left(m)): return .Left(m) case let (.Right(r), .Right(g)): return Either.Right(Box(g.value(r.value))) diff --git a/Swiftx/Functions.swift b/Swiftx/Functions.swift index 10d0bee..5c5708b 100644 --- a/Swiftx/Functions.swift +++ b/Swiftx/Functions.swift @@ -17,19 +17,19 @@ public func const(x : A) -> B -> A { } /// Flip a function's arguments -public func flip(f: ((A, B) -> C), b: B, a: A) -> C { +public func flip(f : ((A, B) -> C), b: B, a: A) -> C { return f(a, b) } /// Flip a function's arguments and return a function that takes /// the arguments in flipped order. -public func flip(f: (A, B) -> C)(b: B, a: A) -> C { +public func flip(f : (A, B) -> C)(b : B, a: A) -> C { return f(a, b) } /// Flip a function's arguments and return a curried function that takes /// the arguments in flipped order. -public func flip(f: A -> B -> C) -> B -> A -> C { +public func flip(f : A -> B -> C) -> B -> A -> C { return { b in { a in f(a)(b) } } } @@ -38,8 +38,8 @@ public func flip(f: A -> B -> C) -> B -> A -> C { /// f : B -> C /// g : A -> B /// (f • g)(x) === f(g(x)) : A -> B -> C -public func • (f: B -> C, g: A -> B) -> A -> C { - return { (a: A) -> C in +public func • (f : B -> C, g: A -> B) -> A -> C { + return { (a : A) -> C in return f(g(a)) } } @@ -53,7 +53,7 @@ public func • (f: B -> C, g: A -> B) -> A -> C { /// f § g § h § x = f(g(h(x))) /// /// Key Chord: ⌥ + 6 -public func § (f: A -> B, a: A) -> B { +public func § (f : A -> B, a: A) -> B { return f(a) } @@ -65,7 +65,7 @@ public func § (f: A -> B, a: A) -> B { /// f <| g <| h <| x = f (g (h x)) /// /// Acts as a synonym for §. -public func <| (f: A -> B, a: A) -> B { +public func <| (f : A -> B, a: A) -> B { return f(a) } @@ -81,7 +81,7 @@ public func <| (f: A -> B, a: A) -> B { /// 1 |> { $0.advancedBy($0) } /// |> { $0.advancedBy($0) } /// |> { $0 * $0 } -public func |> (a: A, f: A -> B) -> B { +public func |> (a : A, f: A -> B) -> B { return f(a) } diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 8fc6a31..ec2d70b 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -7,13 +7,13 @@ // /// Lifts a value into an Optional. -public func pure(a: A) -> A? { +public func pure(a : A) -> A? { return .Some(a) } /// Fmap | If the Optional is None, ignores the function and returns None. If the Optional is Some, /// applies the function to the Some value and returns the result in a new Some. -public func <^> (f: A -> B, a: A?) -> B? { +public func <^> (f : A -> B, a: A?) -> B? { if let x = a { return (f(x)) } else { @@ -24,7 +24,7 @@ public func <^> (f: A -> B, a: A?) -> B? { /// Ap | Given an Optional B> and an Optional, returns an Optional. If the `f` or `a' /// param is None, simply returns None. Otherwise the function taken from Some(f) is applied to the /// value from Some(a) and a Some is returned. -public func <*> (f: (A -> B)?, a: A?) -> B? { +public func <*> (f : (A -> B)?, a: A?) -> B? { if f != nil && a != nil { return (f!(a!)) } else { @@ -34,7 +34,7 @@ public func <*> (f: (A -> B)?, a: A?) -> B? { /// Bind | Given an Optional, and a function from A -> Optional, applies the function `f` if /// `a` is Some, otherwise the function is ignored and None is returned. -public func >>- (a: A?, f: A -> B?) -> B? { +public func >>- (a : A?, f: A -> B?) -> B? { if let x = a { return f(x) } else { diff --git a/Swiftx/Result.swift b/Swiftx/Result.swift index b2a4cf1..c5236b6 100644 --- a/Swiftx/Result.swift +++ b/Swiftx/Result.swift @@ -36,7 +36,7 @@ public enum Result { /// Much like the ?? operator for Optional types, takes a value and a function, /// and if the Result is Error, returns the error, otherwise maps the function over /// the value in Value and returns that value. - public func fold(value: B, f: V -> B) -> B { + public func fold(value : B, f: V -> B) -> B { switch self { case Error(_): return value @@ -48,17 +48,17 @@ public enum Result { /// Named function for `>>-`. If the Result is Error, simply returns /// a New Error with the value of the receiver. If Value, applies the function `f` /// and returns the result. - public func flatMap(f: V -> Result) -> Result { + public func flatMap(f : V -> Result) -> Result { return self >>- f } /// Creates an Error with the given value. - public static func error(e: NSError) -> Result { + public static func error(e : NSError) -> Result { return .Error(e) } /// Creates a Value with the given value. - public static func value(v: V) -> Result { + public static func value(v : V) -> Result { return .Value(Box(v)) } } @@ -160,7 +160,7 @@ public func !! (fn : (A, B, C, D, E, NSErrorPointer) -> F, t : /// MARK: Equatable -public func == (lhs: Result, rhs: Result) -> Bool { +public func == (lhs : Result, rhs: Result) -> Bool { switch (lhs, rhs) { case let (.Error(l), .Error(r)) where l == r: return true @@ -171,21 +171,21 @@ public func == (lhs: Result, rhs: Result) -> Bool { } } -public func != (lhs: Result, rhs: Result) -> Bool { +public func != (lhs : Result, rhs: Result) -> Bool { return !(lhs == rhs) } /// MARK: Functor, Applicative, Monad /// Applicative `pure` function, lifts a value into a Value. -public func pure(a: V) -> Result { +public func pure(a : V) -> Result { return .Value(Box(a)) } /// Functor `fmap`. If the Result is Error, ignores the function and returns the Error. /// If the Result is Value, applies the function to the Right value and returns the result /// in a new Value. -public func <^> (f: VA -> VB, a: Result) -> Result { +public func <^> (f : VA -> VB, a: Result) -> Result { switch a { case let .Error(l): return .Error(l) @@ -198,11 +198,11 @@ public func <^> (f: VA -> VB, a: Result) -> Result { /// returns a Result. If the `f` or `a' param is an Error, simply returns an Error with the /// same value. Otherwise the function taken from Value(f) is applied to the value from Value(a) /// And a Value is returned. -public func <*> (f: Result VB>, a: Result) -> Result { +public func <*> (f : Result VB>, a: Result) -> Result { switch (a, f) { case let (.Error(l), _): return .Error(l) - case let (.Value(r), .Error(m)): + case let (.Value(_), .Error(m)): return .Error(m) case let (.Value(r), .Value(g)): return Result.Value(Box(g.value(r.value))) @@ -212,7 +212,7 @@ public func <*> (f: Result VB>, a: Result) -> Result { /// Monadic `bind`. Given an Result, and a function from VA -> Result, /// applies the function `f` if `a` is Value, otherwise the function is ignored and an Error /// with the Error value from `a` is returned. -public func >>- (a: Result, f: VA -> Result) -> Result { +public func >>- (a : Result, f: VA -> Result) -> Result { switch a { case let .Error(l): return .Error(l) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index 53289dc..686ef69 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -175,46 +175,46 @@ public postfix func <<(lhs : Int) -> Int -> Int { prefix operator ... {} postfix operator ... {} -public prefix func ... (end: T) -> T -> ClosedInterval { +public prefix func ... (end : T) -> T -> ClosedInterval { return { start in start...end } } -public postfix func ... (start: T) -> T -> ClosedInterval { +public postfix func ... (start : T) -> T -> ClosedInterval { return { end in start...end } } -public prefix func ... (end: Pos) -> Pos -> Range { +public prefix func ... (end : Pos) -> Pos -> Range { return { start in start...end } } -public postfix func ... (start: Pos) -> Pos -> Range { +public postfix func ... (start : Pos) -> Pos -> Range { return { end in start...end } } -public prefix func ... (maximum: Pos) -> Pos -> Range { +public prefix func ... (maximum : Pos) -> Pos -> Range { return { minimum in minimum...maximum } } -public postfix func ... (minimum: Pos) -> Pos -> Range { +public postfix func ... (minimum : Pos) -> Pos -> Range { return { maximum in minimum...maximum } } prefix operator ..< {} postfix operator ..< {} -public prefix func ..< (end: Pos) -> Pos -> Range { +public prefix func ..< (end : Pos) -> Pos -> Range { return { start in start..(start: Pos) -> Pos -> Range { +public postfix func ..< (start : Pos) -> Pos -> Range { return { end in start..(maximum: Pos) -> Pos -> Range { +public prefix func ..< (maximum : Pos) -> Pos -> Range { return { minimum in minimum..(minimum: Pos) -> Pos -> Range { +public postfix func ..< (minimum : Pos) -> Pos -> Range { return { maximum in minimum..(lhs : T) -> T -> T { prefix operator ^ {} postfix operator ^ {} -public prefix func ^ (b: T) -> T -> T { +public prefix func ^ (b : T) -> T -> T { return { a in a ^ b } } -public postfix func ^ (a: T) -> T -> T { +public postfix func ^ (a : T) -> T -> T { return { b in a ^ b } } @@ -376,11 +376,11 @@ public postfix func ^(lhs : UInt32) -> UInt32 -> UInt32 { prefix operator | {} postfix operator | {} -public prefix func | (b: T) -> T -> T { +public prefix func | (b : T) -> T -> T { return { a in a | b } } -public postfix func | (a: T) -> T -> T { +public postfix func | (a : T) -> T -> T { return { b in a | b } } @@ -466,11 +466,11 @@ public postfix func |(lhs : UInt32) -> UInt32 -> UInt32 { prefix operator ?? {} -public prefix func ?? (defaultValue: T) -> T? -> T { +public prefix func ?? (defaultValue : T) -> T? -> T { return { optional in optional ?? defaultValue } } -public prefix func ?? (defaultValue: T?) -> T? -> T? { +public prefix func ?? (defaultValue : T?) -> T? -> T? { return { optional in optional ?? defaultValue } } @@ -1224,14 +1224,6 @@ public postfix func ==(lhs : SetIndex) -> SetIndex -> Bool { return { rhs in lhs == rhs } } -public prefix func == (rhs : CFunctionPointer) -> CFunctionPointer -> Bool { - return { lhs in lhs == rhs } -} - -public postfix func == (lhs : CFunctionPointer) -> CFunctionPointer -> Bool { - return { rhs in lhs == rhs } -} - public prefix func == (rhs : HalfOpenInterval) -> HalfOpenInterval -> Bool { return { lhs in lhs == rhs } } @@ -1392,11 +1384,11 @@ public prefix func ==(rhs : UInt8) -> UInt8 -> Bool { return { lhs in lhs == rhs } } -public prefix func ==(y: ObjectIdentifier) -> ObjectIdentifier -> Bool { +public prefix func ==(y : ObjectIdentifier) -> ObjectIdentifier -> Bool { return { x in x == y } } -public postfix func ==(x: ObjectIdentifier) -> ObjectIdentifier -> Bool { +public postfix func ==(x : ObjectIdentifier) -> ObjectIdentifier -> Bool { return { y in x == y } } @@ -1416,11 +1408,11 @@ public postfix func == (lhs : ReverseRandomAccessIndex) -> ReverseRandomAc return { rhs in lhs == rhs } } -public prefix func == (y: T) -> T -> Bool { +public prefix func == (y : T) -> T -> Bool { return { x in x == y } } -public postfix func == (x: T) -> T -> Bool { +public postfix func == (x : T) -> T -> Bool { return { y in x == y } } @@ -1604,14 +1596,6 @@ public postfix func !=(lhs : SetIndex) -> SetIndex -> Bool { return { rhs in lhs != rhs } } -public prefix func != (rhs : CFunctionPointer) -> CFunctionPointer -> Bool { - return { lhs in lhs != rhs } -} - -public postfix func != (lhs : CFunctionPointer) -> CFunctionPointer -> Bool { - return { rhs in lhs != rhs } -} - public prefix func != (rhs : HalfOpenInterval) -> HalfOpenInterval -> Bool { return { lhs in lhs != rhs } } @@ -1855,22 +1839,6 @@ public postfix func <=(lhs : UInt8) -> UInt8 -> Bool { return { rhs in lhs <= rhs } } -public prefix func <= (rhs : T) -> T -> Bool { - return { lhs in lhs <= rhs } -} - -public postfix func <= (lhs : T) -> T -> Bool { - return { rhs in lhs <= rhs } -} - -public prefix func <= (rhs : T?) -> T? -> Bool { - return { lhs in lhs <= rhs } -} - -public postfix func <= (lhs : T?) -> T? -> Bool { - return { rhs in lhs <= rhs } -} - public prefix func <=(rhs : Int) -> Int -> Bool { return { lhs in lhs <= rhs } } @@ -1954,22 +1922,6 @@ public postfix func >=(lhs : UInt8) -> UInt8 -> Bool { return { rhs in lhs >= rhs } } -public prefix func >= (rhs : T) -> T -> Bool { - return { lhs in lhs >= rhs } -} - -public postfix func >= (lhs : T) -> T -> Bool { - return { rhs in lhs >= rhs } -} - -public prefix func >= (rhs : T?) -> T? -> Bool { - return { lhs in lhs >= rhs } -} - -public postfix func >= (lhs : T?) -> T? -> Bool { - return { rhs in lhs >= rhs } -} - public prefix func >=(rhs : Int) -> Int -> Bool { return { lhs in lhs >= rhs } } @@ -2105,10 +2057,6 @@ public prefix func >(rhs : String) -> String -> Bool { return { lhs in lhs > rhs } } -public prefix func > (rhs : T?) -> T? -> Bool { - return { lhs in lhs > rhs } -} - #if os(OSX) public prefix func >(rhs : Swift.Float80) -> Swift.Float80 -> Bool { return { lhs in lhs > rhs } @@ -2210,10 +2158,6 @@ public postfix func <(lhs : String) -> String -> Bool { return { rhs in lhs < rhs } } -public postfix func < (lhs : T?) -> T? -> Bool { - return { rhs in lhs < rhs } -} - #if os(OSX) public postfix func <(lhs : Swift.Float80) -> Swift.Float80 -> Bool { return { rhs in lhs < rhs } diff --git a/SwiftxTests/Info.plist b/SwiftxTests/Info.plist index 7ce8f4d..6d32c15 100644 --- a/SwiftxTests/Info.plist +++ b/SwiftxTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - io.maxs.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName From a028e79f580f76ccf13a790964215b312fb7a5a0 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 8 Jun 2015 16:32:14 -0600 Subject: [PATCH 02/48] Remove Boxing --- Swiftx/Array.swift | 11 +++------ Swiftx/Either.swift | 53 +++++++++++++++++-------------------------- Swiftx/Optional.swift | 9 ++------ Swiftx/Result.swift | 50 ++++++++++++++++++++-------------------- 4 files changed, 51 insertions(+), 72 deletions(-) diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index c2ed1c1..6bb42b5 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -6,20 +6,15 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// Lifts a value into an Array. -public func pure(a : A) -> [A] { - return [a] -} - /// Fmap | Maps a function over the contents of an array and returns a new array of the resulting /// values. -public func <^> (f : A -> B, a: [A]) -> [B] { +public func <^> (f : A -> B, a : [A]) -> [B] { return a.map(f) } /// Ap | Given an [A -> B] and an [A], returns a [B]. Applies the function at each index in `f` to /// every index in `a` and returns the results in a new array. -public func <*> (f : [(A -> B)], a: [A]) -> [B] { +public func <*> (f : [(A -> B)], a : [A]) -> [B] { var re = [B]() for g in f { for h in a { @@ -31,7 +26,7 @@ public func <*> (f : [(A -> B)], a: [A]) -> [B] { /// Bind | Given an [A], and a function from A -> [B], applies the function `f` to every element in /// [A] and returns the result. -public func >>- (a : [A], f: A -> [B]) -> [B] { +public func >>- (a : [A], f : A -> [B]) -> [B] { var re = [B]() for x in a { re.extend(f(x)) diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 93f2595..6b88079 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -15,13 +15,13 @@ import class Foundation.NSError /// convention, the Left constructor is used to hold an error value and the Right constructor is /// used to hold a correct value (mnemonic: "right" also means "correct"). public enum Either { - case Left(Box) - case Right(Box) + case Left(L) + case Right(R) /// Converts a Either to a Result, which is a more specialized type that /// contains an NSError or a value. public func toResult(ev : L -> NSError) -> Result { - return either(onLeft : { e in Result.Error(ev(e)) }, onRight: { v in .Value(Box(v)) }); + return either(onLeft: { Result.Error(ev($0)) }, onRight: { .Value($0) }); } @@ -29,7 +29,7 @@ public enum Either { /// and if the Either is Left, returns the value, otherwise maps the function over /// the value in Right and returns that value. public func fold(value : B, f : R -> B) -> B { - return either(onLeft : { _ in value }, onRight: { r in f(r) }); + return either(onLeft: const(value), onRight: f); } /// Named function for `>>-`. If the Either is Left, simply returns @@ -39,49 +39,38 @@ public enum Either { return self >>- f } - /// Creates a Left with the given value. - public static func left(l : L) -> Either { - return .Left(Box(l)) - } - - /// Creates a Right with the given value. - public static func right(r : R) -> Either { - return .Right(Box(r)) - } - /// Case analysis for the Either type. If the value is Left(a), apply the first function to a; /// if it is Right(b), apply the second function to b. public func either(onLeft onLeft : L -> A, onRight : R -> A) -> A { switch self { - case let Left(e): - return onLeft(e.value) - case let Right(e): - return onRight(e.value) + case let .Left(e): + return onLeft(e) + case let .Right(e): + return onRight(e) } } /// Determines if this Either value is a Left. public func isLeft() -> Bool { switch self { - case Left(_): return true - case Right(_): return false + case Left(_): + return true + case Right(_): + return false } } /// Determines if this Either value is a Right. public func isRight() -> Bool { switch self { - case Left(_): return false - case Right(_): return true + case Left(_): + return false + case Right(_): + return true } } } -/// Applicative `pure` function, lifts a value into an Right. -public func pure(a : R) -> Either { - return .Right(Box(a)) -} - /// Fmap | If the Either is Left, ignores the function and returns the Left. If the Either is Right, /// applies the function to the Right value and returns the result in a new Right. public func <^> (f : RA -> RB, a : Either) -> Either { @@ -89,7 +78,7 @@ public func <^> (f : RA -> RB, a : Either) -> Either { case let .Left(l): return .Left(l) case let .Right(r): - return Either.Right(Box(f(r.value))) + return Either.Right(f(r)) } } @@ -103,7 +92,7 @@ public func <*> (f : Either RB>, a : Either) -> Eithe case let (.Right(_), .Left(m)): return .Left(m) case let (.Right(r), .Right(g)): - return Either.Right(Box(g.value(r.value))) + return Either.Right(g(r)) } } @@ -115,16 +104,16 @@ public func >>- (a : Either, f : RA -> Either) -> Eithe case let .Left(l): return .Left(l) case let .Right(r): - return f(r.value) + return f(r) } } /// MARK : Equatable public func == (lhs : Either, rhs : Either) -> Bool { switch (lhs, rhs) { - case let (.Left(l), .Left(r)) where l.value == r.value: + case let (.Left(l), .Left(r)) where l == r: return true - case let (.Right(l), .Right(r)) where l.value == r.value: + case let (.Right(l), .Right(r)) where l == r: return true default: return false diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index ec2d70b..6bd6b5e 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -6,14 +6,9 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// Lifts a value into an Optional. -public func pure(a : A) -> A? { - return .Some(a) -} - /// Fmap | If the Optional is None, ignores the function and returns None. If the Optional is Some, /// applies the function to the Some value and returns the result in a new Some. -public func <^> (f : A -> B, a: A?) -> B? { +public func <^> (f : A -> B, a : A?) -> B? { if let x = a { return (f(x)) } else { @@ -34,7 +29,7 @@ public func <*> (f : (A -> B)?, a: A?) -> B? { /// Bind | Given an Optional, and a function from A -> Optional, applies the function `f` if /// `a` is Some, otherwise the function is ignored and None is returned. -public func >>- (a : A?, f: A -> B?) -> B? { +public func >>- (a : A?, f : A -> B?) -> B? { if let x = a { return f(x) } else { diff --git a/Swiftx/Result.swift b/Swiftx/Result.swift index c5236b6..b389a2e 100644 --- a/Swiftx/Result.swift +++ b/Swiftx/Result.swift @@ -13,13 +13,13 @@ import typealias Foundation.NSErrorPointer /// only contain an NSError. public enum Result { case Error(NSError) - case Value(Box) + case Value(V) public init(_ e: NSError?, _ v: V) { if let ex = e { self = Result.Error(ex) } else { - self = Result.Value(Box(v)) + self = Result.Value(v) } } @@ -27,9 +27,9 @@ public enum Result { public func toEither() -> Either { switch self { case let Error(e): - return .Left(Box(e)) + return .Left(e) case let Value(v): - return Either.Right(Box(v.value)) + return Either.Right(v) } } @@ -41,7 +41,7 @@ public enum Result { case Error(_): return value case let Value(v): - return f(v.value) + return f(v) } } @@ -59,7 +59,7 @@ public enum Result { /// Creates a Value with the given value. public static func value(v : V) -> Result { - return .Value(Box(v)) + return .Value(v) } } @@ -70,7 +70,7 @@ public enum Result { public func from(fn : (NSErrorPointer) -> A) -> Result { var err : NSError? = nil let b = fn(&err) - return (err != nil) ? .Error(err!) : .Value(Box(b)) + return (err != nil) ? .Error(err!) : .Value(b) } /// Takes a 1-ary function that can potentially raise an error and constructs a Result depending on @@ -79,7 +79,7 @@ public func from(fn : (A, NSErrorPointer) -> B) -> A -> Result { return { a in var err : NSError? = nil let b = fn(a, &err) - return (err != nil) ? .Error(err!) : .Value(Box(b)) + return (err != nil) ? .Error(err!) : .Value(b) } } @@ -89,7 +89,7 @@ public func from(fn : (A, B, NSErrorPointer) -> C) -> A -> B -> Result< return { a in { b in var err : NSError? = nil let c = fn(a, b, &err) - return (err != nil) ? .Error(err!) : .Value(Box(c)) + return (err != nil) ? .Error(err!) : .Value(c) } } } @@ -99,7 +99,7 @@ public func from(fn : (A, B, C, NSErrorPointer) -> D) -> A -> B -> C return { a in { b in { c in var err : NSError? = nil let d = fn(a, b, c, &err) - return (err != nil) ? .Error(err!) : .Value(Box(d)) + return (err != nil) ? .Error(err!) : .Value(d) } } } } @@ -109,7 +109,7 @@ public func from(fn : (A, B, C, D, NSErrorPointer) -> E) -> A -> return { a in { b in { c in { d in var err : NSError? = nil let e = fn(a, b, c, d, &err) - return (err != nil) ? .Error(err!) : .Value(Box(e)) + return (err != nil) ? .Error(err!) : .Value(e) } } } } } @@ -119,7 +119,7 @@ public func from(fn : (A, B, C, D, E, NSErrorPointer) -> F) -> return { a in { b in { c in { d in { e in var err : NSError? = nil let f = fn(a, b, c, d, e, &err) - return (err != nil) ? .Error(err!) : .Value(Box(f)) + return (err != nil) ? .Error(err!) : .Value(f) } } } } } } @@ -127,35 +127,35 @@ public func from(fn : (A, B, C, D, E, NSErrorPointer) -> F) -> public func !! (fn : (A, NSErrorPointer) -> B, a : A) -> Result { var err : NSError? = nil let b = fn(a, &err) - return (err != nil) ? .Error(err!) : .Value(Box(b)) + return (err != nil) ? .Error(err!) : .Value(b) } /// Infix 2-ary from public func !! (fn : (A, B, NSErrorPointer) -> C, t : (A, B)) -> Result { var err : NSError? = nil let c = fn(t.0, t.1, &err) - return (err != nil) ? .Error(err!) : .Value(Box(c)) + return (err != nil) ? .Error(err!) : .Value(c) } /// Infix 3-ary from public func !! (fn : (A, B, C, NSErrorPointer) -> D, t : (A, B, C)) -> Result { var err : NSError? = nil let d = fn(t.0, t.1, t.2, &err) - return (err != nil) ? .Error(err!) : .Value(Box(d)) + return (err != nil) ? .Error(err!) : .Value(d) } /// Infix 4-ary from public func !! (fn : (A, B, C, D, NSErrorPointer) -> E, t : (A, B, C, D)) -> Result { var err : NSError? = nil let e = fn(t.0, t.1, t.2, t.3, &err) - return (err != nil) ? .Error(err!) : .Value(Box(e)) + return (err != nil) ? .Error(err!) : .Value(e) } /// Infix 5-ary from public func !! (fn : (A, B, C, D, E, NSErrorPointer) -> F, t : (A, B, C, D, E)) -> Result { var err : NSError? = nil let f = fn(t.0, t.1, t.2, t.3, t.4, &err) - return (err != nil) ? .Error(err!) : .Value(Box(f)) + return (err != nil) ? .Error(err!) : .Value(f) } /// MARK: Equatable @@ -164,7 +164,7 @@ public func == (lhs : Result, rhs: Result) -> Bool { switch (lhs, rhs) { case let (.Error(l), .Error(r)) where l == r: return true - case let (.Value(l), .Value(r)) where l.value == r.value: + case let (.Value(l), .Value(r)) where l == r: return true default: return false @@ -179,18 +179,18 @@ public func != (lhs : Result, rhs: Result) -> Bool { /// Applicative `pure` function, lifts a value into a Value. public func pure(a : V) -> Result { - return .Value(Box(a)) + return .Value(a) } /// Functor `fmap`. If the Result is Error, ignores the function and returns the Error. /// If the Result is Value, applies the function to the Right value and returns the result /// in a new Value. -public func <^> (f : VA -> VB, a: Result) -> Result { +public func <^> (f : VA -> VB, a : Result) -> Result { switch a { case let .Error(l): return .Error(l) case let .Value(r): - return Result.Value(Box(f(r.value))) + return Result.Value(f(r)) } } @@ -198,25 +198,25 @@ public func <^> (f : VA -> VB, a: Result) -> Result { /// returns a Result. If the `f` or `a' param is an Error, simply returns an Error with the /// same value. Otherwise the function taken from Value(f) is applied to the value from Value(a) /// And a Value is returned. -public func <*> (f : Result VB>, a: Result) -> Result { +public func <*> (f : Result VB>, a : Result) -> Result { switch (a, f) { case let (.Error(l), _): return .Error(l) case let (.Value(_), .Error(m)): return .Error(m) case let (.Value(r), .Value(g)): - return Result.Value(Box(g.value(r.value))) + return Result.Value(g(r)) } } /// Monadic `bind`. Given an Result, and a function from VA -> Result, /// applies the function `f` if `a` is Value, otherwise the function is ignored and an Error /// with the Error value from `a` is returned. -public func >>- (a : Result, f: VA -> Result) -> Result { +public func >>- (a : Result, f : VA -> Result) -> Result { switch a { case let .Error(l): return .Error(l) case let .Value(r): - return f(r.value) + return f(r) } } From d6f0b28d5c79a4825c676cb4b3f1b7009c64cb7a Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 8 Jun 2015 19:07:16 -0600 Subject: [PATCH 03/48] Add changed sections --- Swiftx/Sections.swift | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index 686ef69..52cbf01 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -1073,6 +1073,14 @@ public postfix func ===(lhs : AnyObject?) -> AnyObject? -> Bool { return { rhs in lhs === rhs } } +public prefix func === (rhs : R) -> L -> Bool { + return { lhs in lhs === rhs } +} + +public postfix func === (lhs : L) -> R -> Bool { + return { rhs in lhs === rhs } +} + prefix operator !== {} postfix operator !== {} @@ -1464,6 +1472,22 @@ public postfix func == (lhs : UnsafeMutablePointer) -> UnsafeMutablePointe return { rhs in lhs == rhs } } +public postfix func ==(lhs : AnyForwardIndex) -> AnyForwardIndex -> Bool { + return { rhs in lhs == rhs } +} + +public prefix func ==(rhs : AnyForwardIndex) -> AnyForwardIndex -> Bool { + return { lhs in lhs == rhs } +} + +public postfix func ==(lhs : AnyBidirectionalIndex) -> AnyBidirectionalIndex -> Bool { + return { rhs in lhs == rhs } +} + +public prefix func ==(rhs : AnyBidirectionalIndex) -> AnyBidirectionalIndex -> Bool { + return { lhs in lhs == rhs } +} + prefix operator != {} postfix operator != {} @@ -1903,6 +1927,14 @@ public postfix func <=(lhs : UInt64) -> UInt64 -> Bool { return { rhs in lhs <= rhs } } +public prefix func <=(rhs : T) -> T -> Bool { + return { lhs in lhs <= rhs } +} + +public postfix func <=(lhs : T) -> T -> Bool { + return { rhs in lhs <= rhs } +} + prefix operator >= {} postfix operator >= {} @@ -1986,6 +2018,22 @@ public postfix func >=(lhs : UInt64) -> UInt64 -> Bool { return { rhs in lhs >= rhs } } +public prefix func >=(rhs : T?) -> T? -> Bool { + return { lhs in lhs >= rhs } +} + +public postfix func >=(lhs : T?) -> T? -> Bool { + return { rhs in lhs >= rhs } +} + +public prefix func >=(rhs : T) -> T -> Bool { + return { lhs in lhs >= rhs } +} + +public postfix func >=(lhs : T) -> T -> Bool { + return { rhs in lhs >= rhs } +} + prefix operator > {} // postfix operator > {} @@ -2083,6 +2131,14 @@ public prefix func > (rhs : DictionaryIndex) return { lhs in lhs > rhs } } +public prefix func > (rhs : T?) -> T? -> Bool { + return { lhs in lhs > rhs } +} + +public prefix func > (rhs : T) -> T -> Bool { + return { lhs in lhs > rhs } +} + //prefix operator < {} postfix operator < {} @@ -2184,4 +2240,10 @@ public postfix func < (lhs : DictionaryIndex) return { rhs in lhs < rhs } } +public postfix func < (lhs : T?) -> T? -> Bool { + return { rhs in lhs < rhs } +} +public postfix func < (lhs : T) -> T -> Bool { + return { rhs in lhs < rhs } +} From 29cb721b26d6d4bd07b6958ad5220dbad2a588ed Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 8 Jun 2015 19:18:23 -0600 Subject: [PATCH 04/48] Remove Box --- Swiftx.xcodeproj/project.pbxproj | 6 ------ Swiftx/Box.swift | 37 -------------------------------- SwiftxTests/SectionTests.swift | 11 ---------- 3 files changed, 54 deletions(-) delete mode 100644 Swiftx/Box.swift diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index f8bcbd7..20e3d7d 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; 84A88CF91A70BDB9003D53CF /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CE91A70BDB9003D53CF /* Array.swift */; }; - 84A88CFA1A70BDB9003D53CF /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEA1A70BDB9003D53CF /* Box.swift */; }; 84A88CFB1A70BDB9003D53CF /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; 84A88CFC1A70BDB9003D53CF /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEC1A70BDB9003D53CF /* Error.swift */; }; 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Functions.swift */; }; @@ -29,7 +28,6 @@ 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; 84DF76841B0BDE5400C912B0 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF01A70BDB9003D53CF /* Operators.swift */; }; 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; - 84DF76861B0BDE5400C912B0 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEA1A70BDB9003D53CF /* Box.swift */; }; 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CE91A70BDB9003D53CF /* Array.swift */; }; @@ -82,7 +80,6 @@ 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; - 84A88CEA1A70BDB9003D53CF /* Box.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; 84A88CEB1A70BDB9003D53CF /* Either.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = ""; usesTabs = 1; }; 84A88CEC1A70BDB9003D53CF /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = ""; }; 84A88CED1A70BDB9003D53CF /* Functions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = ""; }; @@ -179,7 +176,6 @@ 84A88D2B1A70BEE0003D53CF /* Data */ = { isa = PBXGroup; children = ( - 84A88CEA1A70BDB9003D53CF /* Box.swift */, 84A88CEB1A70BDB9003D53CF /* Either.swift */, 84A88CF21A70BDB9003D53CF /* Result.swift */, ); @@ -398,7 +394,6 @@ 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */, 84A88CFB1A70BDB9003D53CF /* Either.swift in Sources */, 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */, - 84A88CFA1A70BDB9003D53CF /* Box.swift in Sources */, 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -419,7 +414,6 @@ 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */, 84DF76841B0BDE5400C912B0 /* Operators.swift in Sources */, 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */, - 84DF76861B0BDE5400C912B0 /* Box.swift in Sources */, 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */, 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */, 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */, diff --git a/Swiftx/Box.swift b/Swiftx/Box.swift deleted file mode 100644 index 6d3fdee..0000000 --- a/Swiftx/Box.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// Box.swift -// Swiftx -// -// Created by Andrew Cobb on 6/9/14. -// Copyright (c) 2014 TypeLift. All rights reserved. -// - -/// An immutable reference type holding a singular value. -/// -/// Boxes are often used when the Swift compiler cannot infer the size of a struct or enum because -/// one of its generic types is being used as a member. -public final class Box { - private let val : () -> T - - public var value : T { return val() } - - public init(@autoclosure(escaping) _ value : () -> T) { - self.val = value - } - - // Type inference fails here. rdar://19347652 - public func map(f : T -> U) -> Box { - return Box(f(self.value)) - } -} - -/// Fmap | Applies a function to the value of the receiver to yield a new box. -public func <^> (f : T -> U, x : Box) -> Box { - return x.map(f) -} - -extension Box : CustomStringConvertible { - public var description: String { - return "Box(\(String(value)))" - } -} diff --git a/SwiftxTests/SectionTests.swift b/SwiftxTests/SectionTests.swift index 5582984..77ce2a4 100644 --- a/SwiftxTests/SectionTests.swift +++ b/SwiftxTests/SectionTests.swift @@ -168,15 +168,4 @@ class SectionTests: XCTestCase { XCTAssertTrue(s.map(!=5) == t, "") } - - func testReferenceEqualitySections() { - let x = Box(5) - let y = Box(5) - let z = Box(5) - - let s = [x, y, z] - let t = s.map({ x in x === y }) - - XCTAssertTrue(s.map(===y) == t, "") - } } From 87a1a8577e5bc67bfdb551dfbd1fb7d895cf8cd3 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 23 Jun 2015 16:25:10 -0600 Subject: [PATCH 05/48] Swap _RawOptionSetType for RawRepresentable --- Swiftx/Sections.swift | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index 52cbf01..ed6c5be 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -285,14 +285,6 @@ public postfix func &- (lhs : T) -> T -> T { prefix operator ^ {} postfix operator ^ {} -public prefix func ^ (b : T) -> T -> T { - return { a in a ^ b } -} - -public postfix func ^ (a : T) -> T -> T { - return { b in a ^ b } -} - public prefix func ^(rhs : UInt8) -> UInt8 -> UInt8 { return { lhs in lhs ^ rhs } } @@ -376,14 +368,6 @@ public postfix func ^(lhs : UInt32) -> UInt32 -> UInt32 { prefix operator | {} postfix operator | {} -public prefix func | (b : T) -> T -> T { - return { a in a | b } -} - -public postfix func | (a : T) -> T -> T { - return { b in a | b } -} - public prefix func |(rhs : UInt8) -> UInt8 -> UInt8 { return { lhs in lhs | rhs } } @@ -1182,11 +1166,11 @@ public prefix func ==(rhs : Double) -> Double -> Bool { return { lhs in lhs == rhs } } -public prefix func == (rhs : T) -> T -> Bool { +public prefix func == (rhs : T) -> T -> Bool { return { lhs in lhs == rhs } } -public postfix func == (lhs : T) -> T -> Bool { +public postfix func == (lhs : T) -> T -> Bool { return { rhs in lhs == rhs } } @@ -1570,11 +1554,11 @@ public prefix func !=(rhs : Double) -> Double -> Bool { return { lhs in lhs != rhs } } -public prefix func != (rhs : T) -> T -> Bool { +public prefix func != (rhs : T) -> T -> Bool { return { lhs in lhs != rhs } } -public postfix func != (lhs : T) -> T -> Bool { +public postfix func != (lhs : T) -> T -> Bool { return { rhs in lhs != rhs } } From dca26b897caaf356cf26077e04b406177e2931be Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 23 Jun 2015 16:25:17 -0600 Subject: [PATCH 06/48] Remove last pure --- Swiftx/Either.swift | 1 + Swiftx/Result.swift | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 6b88079..9a879df 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -109,6 +109,7 @@ public func >>- (a : Either, f : RA -> Either) -> Eithe } /// MARK : Equatable + public func == (lhs : Either, rhs : Either) -> Bool { switch (lhs, rhs) { case let (.Left(l), .Left(r)) where l == r: diff --git a/Swiftx/Result.swift b/Swiftx/Result.swift index b389a2e..8f0523c 100644 --- a/Swiftx/Result.swift +++ b/Swiftx/Result.swift @@ -177,11 +177,6 @@ public func != (lhs : Result, rhs: Result) -> Bool { /// MARK: Functor, Applicative, Monad -/// Applicative `pure` function, lifts a value into a Value. -public func pure(a : V) -> Result { - return .Value(a) -} - /// Functor `fmap`. If the Result is Error, ignores the function and returns the Error. /// If the Result is Value, applies the function to the Right value and returns the result /// in a new Value. From cf8425e862f83269a99d38c09119097b6685c64c Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 7 Jul 2015 20:52:05 -0600 Subject: [PATCH 07/48] Depend on Operadics --- Cartfile | 0 Cartfile.private | 2 ++ Cartfile.resolved | 1 + Swiftx.xcodeproj/project.pbxproj | 12 +++---- Swiftx/Operators.swift | 62 -------------------------------- 5 files changed, 9 insertions(+), 68 deletions(-) create mode 100644 Cartfile create mode 100644 Cartfile.private create mode 100644 Cartfile.resolved delete mode 100644 Swiftx/Operators.swift diff --git a/Cartfile b/Cartfile new file mode 100644 index 0000000..e69de29 diff --git a/Cartfile.private b/Cartfile.private new file mode 100644 index 0000000..024a97a --- /dev/null +++ b/Cartfile.private @@ -0,0 +1,2 @@ +github "typelift/Operadics" + diff --git a/Cartfile.resolved b/Cartfile.resolved new file mode 100644 index 0000000..105d648 --- /dev/null +++ b/Cartfile.resolved @@ -0,0 +1 @@ +github "typelift/Operadics" "v0.1.0" diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 20e3d7d..e10bc09 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 822A5FBD1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; + 822A5FBE1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; @@ -15,7 +17,6 @@ 84A88CFC1A70BDB9003D53CF /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEC1A70BDB9003D53CF /* Error.swift */; }; 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Functions.swift */; }; 84A88CFF1A70BDB9003D53CF /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; - 84A88D001A70BDB9003D53CF /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF01A70BDB9003D53CF /* Operators.swift */; }; 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF11A70BDB9003D53CF /* Optional.swift */; }; 84A88D021A70BDB9003D53CF /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; @@ -26,7 +27,6 @@ 84DF76811B0BDE4E00C912B0 /* Swiftx.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88D071A70BDDA003D53CF /* Swiftx.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84DF76821B0BDE5400C912B0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Functions.swift */; }; 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; - 84DF76841B0BDE5400C912B0 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF01A70BDB9003D53CF /* Operators.swift */; }; 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; @@ -77,6 +77,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; }; 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; @@ -85,7 +86,6 @@ 84A88CED1A70BDB9003D53CF /* Functions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = ""; }; 84A88CEE1A70BDB9003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84A88CEF1A70BDB9003D53CF /* Nothing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nothing.swift; sourceTree = ""; }; - 84A88CF01A70BDB9003D53CF /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; 84A88CF11A70BDB9003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; }; 84A88CF21A70BDB9003D53CF /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 84A88CF31A70BDB9003D53CF /* Sections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sections.swift; sourceTree = ""; }; @@ -156,7 +156,7 @@ children = ( 84A88CED1A70BDB9003D53CF /* Functions.swift */, 84A88CEF1A70BDB9003D53CF /* Nothing.swift */, - 84A88CF01A70BDB9003D53CF /* Operators.swift */, + 822A5FBC1B4CC78A00F48B0B /* Operators.swift */, 84A88CF31A70BDB9003D53CF /* Sections.swift */, 84A88D2B1A70BEE0003D53CF /* Data */, 84A88D2C1A70BEEA003D53CF /* Stdlib */, @@ -389,12 +389,12 @@ 84A88D021A70BDB9003D53CF /* Result.swift in Sources */, 84A88CFC1A70BDB9003D53CF /* Error.swift in Sources */, 84A88CFF1A70BDB9003D53CF /* Nothing.swift in Sources */, - 84A88D001A70BDB9003D53CF /* Operators.swift in Sources */, 84A88CF91A70BDB9003D53CF /* Array.swift in Sources */, 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */, 84A88CFB1A70BDB9003D53CF /* Either.swift in Sources */, 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */, 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */, + 822A5FBD1B4CC78A00F48B0B /* Operators.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -412,13 +412,13 @@ files = ( 84DF76821B0BDE5400C912B0 /* Functions.swift in Sources */, 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */, - 84DF76841B0BDE5400C912B0 /* Operators.swift in Sources */, 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */, 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */, 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */, 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */, 84DF768A1B0BDE5400C912B0 /* Error.swift in Sources */, 84DF768B1B0BDE5400C912B0 /* Optional.swift in Sources */, + 822A5FBE1B4CC78A00F48B0B /* Operators.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Swiftx/Operators.swift b/Swiftx/Operators.swift deleted file mode 100644 index 28fae1e..0000000 --- a/Swiftx/Operators.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// Operators.swift -// Swiftx -// -// Created by Robert Widmann on 28/06/2014. -// Copyright (c) 2014 TypeLift. All rights reserved. -// - -/// MARK: Combinators - -/// Compose | Applies one function to the result of another function to produce a third function. -infix operator • { - associativity right - precedence 190 -} - -/// Apply | Applies an argument to a function. -infix operator § { - associativity right - precedence 0 -} - -/// Pipe Backward | Applies the function to its left to an argument on its right. -infix operator <| { - associativity right - precedence 0 -} - -/// Pipe forward | Applies an argument on the left to a function on the right. -infix operator |> { - associativity left - precedence 0 -} - -/// MARK: Control.* - -/// Fmap | Maps a function over the value encapsulated by a functor. -infix operator <^> { - associativity left - precedence 140 -} - -/// Ap | Applies a function encapsulated by a functor to the value encapsulated by another functor. -infix operator <*> { - associativity left - precedence 140 -} - -/// Bind | Sequences and composes two monadic actions by passing the value inside the monad on the -/// left to a function on the right yielding a new monad. -infix operator >>- { - associativity left - precedence 110 -} - -/// MARK: Data.Result - -/// From | Creates a Result given a function that can possibly fail with an error. -infix operator !! { - associativity none - precedence 120 -} From cecc4a0a2af56795134e082b2571c3722b553456 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 8 Jul 2015 15:16:41 -0600 Subject: [PATCH 08/48] Update to Swift beta 3 --- Swiftx/Sections.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index ed6c5be..82aa92b 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -1126,11 +1126,11 @@ public prefix func ==(rhs : String.UTF16View.Index) -> String.UTF16View.Index -> return { lhs in lhs == rhs } } -public postfix func == (lhs : FilterCollectionViewIndex) -> FilterCollectionViewIndex -> Bool { +public postfix func == (lhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { return { rhs in lhs == rhs } } -public prefix func == (rhs : FilterCollectionViewIndex) -> FilterCollectionViewIndex -> Bool { +public prefix func == (rhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { return { lhs in lhs == rhs } } @@ -1384,11 +1384,11 @@ public postfix func ==(x : ObjectIdentifier) -> ObjectIdentifier -> Bool { return { y in x == y } } -public prefix func == (rhs : ReverseBidirectionalIndex) -> ReverseBidirectionalIndex -> Bool { +public prefix func == (rhs : ReverseIndex) -> ReverseIndex -> Bool { return { lhs in lhs == rhs } } -public postfix func == (lhs : ReverseBidirectionalIndex) -> ReverseBidirectionalIndex -> Bool { +public postfix func == (lhs : ReverseIndex) -> ReverseIndex -> Bool { return { rhs in lhs == rhs } } @@ -1514,11 +1514,11 @@ public prefix func !=(rhs : Int) -> Int -> Bool { return { lhs in lhs != rhs } } -public postfix func != (lhs : FilterCollectionViewIndex) -> FilterCollectionViewIndex -> Bool { +public postfix func != (lhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { return { rhs in lhs != rhs } } -public prefix func != (rhs : FilterCollectionViewIndex) -> FilterCollectionViewIndex -> Bool { +public prefix func != (rhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { return { lhs in lhs != rhs } } @@ -1764,11 +1764,11 @@ public postfix func !=(lhs : ObjectIdentifier) -> ObjectIdentifier -> Bool { return { rhs in lhs != rhs } } -public prefix func != (rhs : ReverseBidirectionalIndex) -> ReverseBidirectionalIndex -> Bool { +public prefix func != (rhs : ReverseIndex) -> ReverseIndex -> Bool { return { lhs in lhs != rhs } } -public postfix func != (lhs : ReverseBidirectionalIndex) -> ReverseBidirectionalIndex -> Bool { +public postfix func != (lhs : ReverseIndex) -> ReverseIndex -> Bool { return { rhs in lhs != rhs } } From b51a615c2d3bc2e675474147b39e003f7af6916e Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 15 Jul 2015 12:21:36 -0600 Subject: [PATCH 09/48] Functions -> Combinators --- Cartfile.resolved | 2 +- Swiftx.xcodeproj/project.pbxproj | 12 ++++++------ Swiftx/{Functions.swift => Combinators.swift} | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) rename Swiftx/{Functions.swift => Combinators.swift} (99%) diff --git a/Cartfile.resolved b/Cartfile.resolved index 105d648..38c4267 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "typelift/Operadics" "v0.1.0" +github "typelift/Operadics" "v0.1.2" diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index e10bc09..aa931a3 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 84A88CF91A70BDB9003D53CF /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CE91A70BDB9003D53CF /* Array.swift */; }; 84A88CFB1A70BDB9003D53CF /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; 84A88CFC1A70BDB9003D53CF /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEC1A70BDB9003D53CF /* Error.swift */; }; - 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Functions.swift */; }; + 84A88CFD1A70BDB9003D53CF /* Combinators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Combinators.swift */; }; 84A88CFF1A70BDB9003D53CF /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF11A70BDB9003D53CF /* Optional.swift */; }; 84A88D021A70BDB9003D53CF /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; @@ -25,7 +25,7 @@ 84A88D451A70BFA6003D53CF /* SectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88D341A70BF4C003D53CF /* SectionTests.swift */; }; 84DF76731B0BDE0A00C912B0 /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; }; 84DF76811B0BDE4E00C912B0 /* Swiftx.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88D071A70BDDA003D53CF /* Swiftx.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 84DF76821B0BDE5400C912B0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Functions.swift */; }; + 84DF76821B0BDE5400C912B0 /* Combinators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Combinators.swift */; }; 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; @@ -83,7 +83,7 @@ 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 84A88CEB1A70BDB9003D53CF /* Either.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = ""; usesTabs = 1; }; 84A88CEC1A70BDB9003D53CF /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = ""; }; - 84A88CED1A70BDB9003D53CF /* Functions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Functions.swift; sourceTree = ""; }; + 84A88CED1A70BDB9003D53CF /* Combinators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinators.swift; sourceTree = ""; }; 84A88CEE1A70BDB9003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84A88CEF1A70BDB9003D53CF /* Nothing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nothing.swift; sourceTree = ""; }; 84A88CF11A70BDB9003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; }; @@ -154,7 +154,7 @@ 84A88CE81A70BDB9003D53CF /* Swiftx */ = { isa = PBXGroup; children = ( - 84A88CED1A70BDB9003D53CF /* Functions.swift */, + 84A88CED1A70BDB9003D53CF /* Combinators.swift */, 84A88CEF1A70BDB9003D53CF /* Nothing.swift */, 822A5FBC1B4CC78A00F48B0B /* Operators.swift */, 84A88CF31A70BDB9003D53CF /* Sections.swift */, @@ -392,7 +392,7 @@ 84A88CF91A70BDB9003D53CF /* Array.swift in Sources */, 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */, 84A88CFB1A70BDB9003D53CF /* Either.swift in Sources */, - 84A88CFD1A70BDB9003D53CF /* Functions.swift in Sources */, + 84A88CFD1A70BDB9003D53CF /* Combinators.swift in Sources */, 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */, 822A5FBD1B4CC78A00F48B0B /* Operators.swift in Sources */, ); @@ -410,7 +410,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 84DF76821B0BDE5400C912B0 /* Functions.swift in Sources */, + 84DF76821B0BDE5400C912B0 /* Combinators.swift in Sources */, 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */, 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */, 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */, diff --git a/Swiftx/Functions.swift b/Swiftx/Combinators.swift similarity index 99% rename from Swiftx/Functions.swift rename to Swiftx/Combinators.swift index 5c5708b..f8813bd 100644 --- a/Swiftx/Functions.swift +++ b/Swiftx/Combinators.swift @@ -84,4 +84,3 @@ public func <| (f : A -> B, a: A) -> B { public func |> (a : A, f: A -> B) -> B { return f(a) } - From 166525e3da1183e2e0c9ff978e90a2440a47f7fb Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 15 Jul 2015 12:22:01 -0600 Subject: [PATCH 10/48] Add the (eta-expanded) fix point combinator --- Swiftx/Combinators.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index f8813bd..7a4c6ff 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -84,3 +84,11 @@ public func <| (f : A -> B, a: A) -> B { public func |> (a : A, f: A -> B) -> B { return f(a) } + +/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first +/// point at which further application of x to a function is the same x. +/// +/// x = f(x) +public func fix(f : ((A -> A) -> A -> A)) -> A -> A { + return { x in f(fix(f))(x) } +} From 1c6dde26b94f8589fbd691c38d4ad682cca15fb3 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 15 Jul 2015 12:22:10 -0600 Subject: [PATCH 11/48] Add `on` --- Swiftx/Combinators.swift | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index 7a4c6ff..b1af69b 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -92,3 +92,45 @@ public func |> (a : A, f: A -> B) -> B { public func fix(f : ((A -> A) -> A -> A)) -> A -> A { return { x in f(fix(f))(x) } } + +/// On | Applies the function on its right to both its arguments, then applies the function on its +/// left to the result of both prior applications. +/// +/// f |*| g = { x in { y in f(g(x))(g(y)) } } +/// +/// This function may be useful when a comparing two like objects using a given property, as in: +/// +/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")] +/// let sortedByFirstIndex = arr.sort((<) |*| fst) +public func |*| (o : B -> B -> C, f : A -> B) -> A -> A -> C { + return on(o)(f) +} + +/// On | Applies the function on its right to both its arguments, then applies the function on its +/// left to the result of both prior applications. +/// +/// (+) |*| f = { x, y in f(x) + f(y) } +/// +/// This function may be useful when a comparing two like objects using a given property, as in: +/// +/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")] +/// let sortedByFirstIndex = arr.sort((<) |*| fst) +public func |*| (o : (B, B) -> C, f : A -> B) -> A -> A -> C { + return on(o)(f) +} + +/// On | Applies the function on its right to both its arguments, then applies the function on its +/// left to the result of both prior applications. +/// +/// (+) |*| f = { x in { y in f(x) + f(y) } } +public func on(o : B -> B -> C) -> (A -> B) -> A -> A -> C { + return { f in { x in { y in o(f(x))(f(y)) } } } +} + +/// On | Applies the function on its right to both its arguments, then applies the function on its +/// left to the result of both prior applications. +/// +/// (+) |*| f = { x, y in f(x) + f(y) } +public func on(o : (B, B) -> C) -> (A -> B) -> A -> A -> C { + return { f in { x in { y in o(f(x), f(y)) } } } +} From 46a7c9a4491e38dc10a6256cca68133b1ddcf691 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 15 Jul 2015 12:22:14 -0600 Subject: [PATCH 12/48] Add until --- Swiftx/Combinators.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index b1af69b..8689007 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -134,3 +134,8 @@ public func on(o : B -> B -> C) -> (A -> B) -> A -> A -> C { public func on(o : (B, B) -> C) -> (A -> B) -> A -> A -> C { return { f in { x in { y in o(f(x), f(y)) } } } } + +/// Applies a function to an argument until a given predicate returns true. +public func until(p : A -> Bool) -> (A -> A) -> A -> A { + return { f in { x in p(x) ? x : until(p)(f)(f(x)) } } +} From 50865626937f21c2858d41ef9a2becf317bcd062 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 15 Jul 2015 12:32:07 -0600 Subject: [PATCH 13/48] Cleanup --- Swiftx/Combinators.swift | 12 ++++++------ Swiftx/Optional.swift | 2 +- Swiftx/Result.swift | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index 8689007..95f3390 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -17,13 +17,13 @@ public func const(x : A) -> B -> A { } /// Flip a function's arguments -public func flip(f : ((A, B) -> C), b: B, a: A) -> C { +public func flip(f : ((A, B) -> C), b : B, a : A) -> C { return f(a, b) } /// Flip a function's arguments and return a function that takes /// the arguments in flipped order. -public func flip(f : (A, B) -> C)(b : B, a: A) -> C { +public func flip(f : (A, B) -> C)(b : B, a : A) -> C { return f(a, b) } @@ -38,7 +38,7 @@ public func flip(f : A -> B -> C) -> B -> A -> C { /// f : B -> C /// g : A -> B /// (f • g)(x) === f(g(x)) : A -> B -> C -public func • (f : B -> C, g: A -> B) -> A -> C { +public func • (f : B -> C, g : A -> B) -> A -> C { return { (a : A) -> C in return f(g(a)) } @@ -53,7 +53,7 @@ public func • (f : B -> C, g: A -> B) -> A -> C { /// f § g § h § x = f(g(h(x))) /// /// Key Chord: ⌥ + 6 -public func § (f : A -> B, a: A) -> B { +public func § (f : A -> B, a : A) -> B { return f(a) } @@ -65,7 +65,7 @@ public func § (f : A -> B, a: A) -> B { /// f <| g <| h <| x = f (g (h x)) /// /// Acts as a synonym for §. -public func <| (f : A -> B, a: A) -> B { +public func <| (f : A -> B, a : A) -> B { return f(a) } @@ -81,7 +81,7 @@ public func <| (f : A -> B, a: A) -> B { /// 1 |> { $0.advancedBy($0) } /// |> { $0.advancedBy($0) } /// |> { $0 * $0 } -public func |> (a : A, f: A -> B) -> B { +public func |> (a : A, f : A -> B) -> B { return f(a) } diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 6bd6b5e..457a8b8 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -19,7 +19,7 @@ public func <^> (f : A -> B, a : A?) -> B? { /// Ap | Given an Optional B> and an Optional, returns an Optional. If the `f` or `a' /// param is None, simply returns None. Otherwise the function taken from Some(f) is applied to the /// value from Some(a) and a Some is returned. -public func <*> (f : (A -> B)?, a: A?) -> B? { +public func <*> (f : (A -> B)?, a : A?) -> B? { if f != nil && a != nil { return (f!(a!)) } else { diff --git a/Swiftx/Result.swift b/Swiftx/Result.swift index 8f0523c..af13dcf 100644 --- a/Swiftx/Result.swift +++ b/Swiftx/Result.swift @@ -36,7 +36,7 @@ public enum Result { /// Much like the ?? operator for Optional types, takes a value and a function, /// and if the Result is Error, returns the error, otherwise maps the function over /// the value in Value and returns that value. - public func fold(value : B, f: V -> B) -> B { + public func fold(value : B, f : V -> B) -> B { switch self { case Error(_): return value @@ -160,7 +160,7 @@ public func !! (fn : (A, B, C, D, E, NSErrorPointer) -> F, t : /// MARK: Equatable -public func == (lhs : Result, rhs: Result) -> Bool { +public func == (lhs : Result, rhs : Result) -> Bool { switch (lhs, rhs) { case let (.Error(l), .Error(r)) where l == r: return true @@ -171,7 +171,7 @@ public func == (lhs : Result, rhs: Result) -> Bool { } } -public func != (lhs : Result, rhs: Result) -> Bool { +public func != (lhs : Result, rhs : Result) -> Bool { return !(lhs == rhs) } From 6c0becf6440c7d8dee2e08bf4d39b364c4007496 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 16 Jul 2015 20:09:50 -0600 Subject: [PATCH 14/48] Remove Result --- Swiftx.xcodeproj/project.pbxproj | 6 - Swiftx/Array.swift | 6 +- Swiftx/Either.swift | 12 +- Swiftx/Error.swift | 2 - Swiftx/Result.swift | 217 ------------------------------- 5 files changed, 2 insertions(+), 241 deletions(-) delete mode 100644 Swiftx/Result.swift diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index aa931a3..661fb23 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -18,7 +18,6 @@ 84A88CFD1A70BDB9003D53CF /* Combinators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Combinators.swift */; }; 84A88CFF1A70BDB9003D53CF /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; 84A88D011A70BDB9003D53CF /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF11A70BDB9003D53CF /* Optional.swift */; }; - 84A88D021A70BDB9003D53CF /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; 84A88D081A70BDDA003D53CF /* Swiftx.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88D071A70BDDA003D53CF /* Swiftx.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84A88D351A70BF4C003D53CF /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 84A88D331A70BF4C003D53CF /* Info.plist */; }; @@ -29,7 +28,6 @@ 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEF1A70BDB9003D53CF /* Nothing.swift */; }; 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEB1A70BDB9003D53CF /* Either.swift */; }; - 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF21A70BDB9003D53CF /* Result.swift */; }; 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CE91A70BDB9003D53CF /* Array.swift */; }; 84DF768A1B0BDE5400C912B0 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEC1A70BDB9003D53CF /* Error.swift */; }; 84DF768B1B0BDE5400C912B0 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF11A70BDB9003D53CF /* Optional.swift */; }; @@ -87,7 +85,6 @@ 84A88CEE1A70BDB9003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84A88CEF1A70BDB9003D53CF /* Nothing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nothing.swift; sourceTree = ""; }; 84A88CF11A70BDB9003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; }; - 84A88CF21A70BDB9003D53CF /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 84A88CF31A70BDB9003D53CF /* Sections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sections.swift; sourceTree = ""; }; 84A88D071A70BDDA003D53CF /* Swiftx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Swiftx.h; path = Swiftx/Swiftx.h; sourceTree = ""; }; 84A88D331A70BF4C003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SwiftxTests/Info.plist; sourceTree = ""; }; @@ -177,7 +174,6 @@ isa = PBXGroup; children = ( 84A88CEB1A70BDB9003D53CF /* Either.swift */, - 84A88CF21A70BDB9003D53CF /* Result.swift */, ); name = Data; sourceTree = ""; @@ -386,7 +382,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 84A88D021A70BDB9003D53CF /* Result.swift in Sources */, 84A88CFC1A70BDB9003D53CF /* Error.swift in Sources */, 84A88CFF1A70BDB9003D53CF /* Nothing.swift in Sources */, 84A88CF91A70BDB9003D53CF /* Array.swift in Sources */, @@ -414,7 +409,6 @@ 84DF76831B0BDE5400C912B0 /* Nothing.swift in Sources */, 84DF76851B0BDE5400C912B0 /* Sections.swift in Sources */, 84DF76871B0BDE5400C912B0 /* Either.swift in Sources */, - 84DF76881B0BDE5400C912B0 /* Result.swift in Sources */, 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */, 84DF768A1B0BDE5400C912B0 /* Error.swift in Sources */, 84DF768B1B0BDE5400C912B0 /* Optional.swift in Sources */, diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index 6bb42b5..9d25933 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -27,9 +27,5 @@ public func <*> (f : [(A -> B)], a : [A]) -> [B] { /// Bind | Given an [A], and a function from A -> [B], applies the function `f` to every element in /// [A] and returns the result. public func >>- (a : [A], f : A -> [B]) -> [B] { - var re = [B]() - for x in a { - re.extend(f(x)) - } - return re + return a.flatMap(f) } diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 9a879df..55854e0 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -6,10 +6,7 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -import class Foundation.NSError - -/// The Either type represents values with two possibilities: a value of type Either is either -/// Left or Right . +/// The `Either` type represents values with two possibilities: `.Left(L)` or `.Right(R)`. /// /// The Either type is sometimes used to represent a value which is either correct or an error; by /// convention, the Left constructor is used to hold an error value and the Right constructor is @@ -18,13 +15,6 @@ public enum Either { case Left(L) case Right(R) - /// Converts a Either to a Result, which is a more specialized type that - /// contains an NSError or a value. - public func toResult(ev : L -> NSError) -> Result { - return either(onLeft: { Result.Error(ev($0)) }, onRight: { .Value($0) }); - } - - /// Much like the ?? operator for Optional types, takes a value and a function, /// and if the Either is Left, returns the value, otherwise maps the function over /// the value in Right and returns that value. diff --git a/Swiftx/Error.swift b/Swiftx/Error.swift index 3ed6279..1b58600 100644 --- a/Swiftx/Error.swift +++ b/Swiftx/Error.swift @@ -7,8 +7,6 @@ // /// Immediately terminates the program with an error message. -/// -/// TODO: Find a way to silence this warning [-wunreachable-code] public func error(x : String) -> A { fatalError(x) } diff --git a/Swiftx/Result.swift b/Swiftx/Result.swift deleted file mode 100644 index af13dcf..0000000 --- a/Swiftx/Result.swift +++ /dev/null @@ -1,217 +0,0 @@ -// -// Result.swift -// Swiftx -// -// Created by Maxwell Swadling on 9/06/2014. -// Copyright (c) 2014 Maxwell Swadling. All rights reserved. -// - -import class Foundation.NSError -import typealias Foundation.NSErrorPointer - -/// Result is similar to an Either, except specialized to have an Error case that can -/// only contain an NSError. -public enum Result { - case Error(NSError) - case Value(V) - - public init(_ e: NSError?, _ v: V) { - if let ex = e { - self = Result.Error(ex) - } else { - self = Result.Value(v) - } - } - - /// Converts a Result to a more general Either type. - public func toEither() -> Either { - switch self { - case let Error(e): - return .Left(e) - case let Value(v): - return Either.Right(v) - } - } - - /// Much like the ?? operator for Optional types, takes a value and a function, - /// and if the Result is Error, returns the error, otherwise maps the function over - /// the value in Value and returns that value. - public func fold(value : B, f : V -> B) -> B { - switch self { - case Error(_): - return value - case let Value(v): - return f(v) - } - } - - /// Named function for `>>-`. If the Result is Error, simply returns - /// a New Error with the value of the receiver. If Value, applies the function `f` - /// and returns the result. - public func flatMap(f : V -> Result) -> Result { - return self >>- f - } - - /// Creates an Error with the given value. - public static func error(e : NSError) -> Result { - return .Error(e) - } - - /// Creates a Value with the given value. - public static func value(v : V) -> Result { - return .Value(v) - } -} - -/// MARK: Function Constructors - -/// Takes a function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (NSErrorPointer) -> A) -> Result { - var err : NSError? = nil - let b = fn(&err) - return (err != nil) ? .Error(err!) : .Value(b) -} - -/// Takes a 1-ary function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (A, NSErrorPointer) -> B) -> A -> Result { - return { a in - var err : NSError? = nil - let b = fn(a, &err) - return (err != nil) ? .Error(err!) : .Value(b) - } -} - -/// Takes a 2-ary function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (A, B, NSErrorPointer) -> C) -> A -> B -> Result { - return { a in { b in - var err : NSError? = nil - let c = fn(a, b, &err) - return (err != nil) ? .Error(err!) : .Value(c) - } } -} - -/// Takes a 3-ary function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (A, B, C, NSErrorPointer) -> D) -> A -> B -> C -> Result { - return { a in { b in { c in - var err : NSError? = nil - let d = fn(a, b, c, &err) - return (err != nil) ? .Error(err!) : .Value(d) - } } } -} - -/// Takes a 4-ary function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (A, B, C, D, NSErrorPointer) -> E) -> A -> B -> C -> D -> Result { - return { a in { b in { c in { d in - var err : NSError? = nil - let e = fn(a, b, c, d, &err) - return (err != nil) ? .Error(err!) : .Value(e) - } } } } -} - -/// Takes a 5-ary function that can potentially raise an error and constructs a Result depending on -/// whether the error pointer has been set. -public func from(fn : (A, B, C, D, E, NSErrorPointer) -> F) -> A -> B -> C -> D -> E -> Result { - return { a in { b in { c in { d in { e in - var err : NSError? = nil - let f = fn(a, b, c, d, e, &err) - return (err != nil) ? .Error(err!) : .Value(f) - } } } } } -} - -/// Infix 1-ary from -public func !! (fn : (A, NSErrorPointer) -> B, a : A) -> Result { - var err : NSError? = nil - let b = fn(a, &err) - return (err != nil) ? .Error(err!) : .Value(b) -} - -/// Infix 2-ary from -public func !! (fn : (A, B, NSErrorPointer) -> C, t : (A, B)) -> Result { - var err : NSError? = nil - let c = fn(t.0, t.1, &err) - return (err != nil) ? .Error(err!) : .Value(c) -} - -/// Infix 3-ary from -public func !! (fn : (A, B, C, NSErrorPointer) -> D, t : (A, B, C)) -> Result { - var err : NSError? = nil - let d = fn(t.0, t.1, t.2, &err) - return (err != nil) ? .Error(err!) : .Value(d) -} - -/// Infix 4-ary from -public func !! (fn : (A, B, C, D, NSErrorPointer) -> E, t : (A, B, C, D)) -> Result { - var err : NSError? = nil - let e = fn(t.0, t.1, t.2, t.3, &err) - return (err != nil) ? .Error(err!) : .Value(e) -} - -/// Infix 5-ary from -public func !! (fn : (A, B, C, D, E, NSErrorPointer) -> F, t : (A, B, C, D, E)) -> Result { - var err : NSError? = nil - let f = fn(t.0, t.1, t.2, t.3, t.4, &err) - return (err != nil) ? .Error(err!) : .Value(f) -} - -/// MARK: Equatable - -public func == (lhs : Result, rhs : Result) -> Bool { - switch (lhs, rhs) { - case let (.Error(l), .Error(r)) where l == r: - return true - case let (.Value(l), .Value(r)) where l == r: - return true - default: - return false - } -} - -public func != (lhs : Result, rhs : Result) -> Bool { - return !(lhs == rhs) -} - -/// MARK: Functor, Applicative, Monad - -/// Functor `fmap`. If the Result is Error, ignores the function and returns the Error. -/// If the Result is Value, applies the function to the Right value and returns the result -/// in a new Value. -public func <^> (f : VA -> VB, a : Result) -> Result { - switch a { - case let .Error(l): - return .Error(l) - case let .Value(r): - return Result.Value(f(r)) - } -} - -/// Applicative Functor `apply`. Given an Result VB> and an Result, -/// returns a Result. If the `f` or `a' param is an Error, simply returns an Error with the -/// same value. Otherwise the function taken from Value(f) is applied to the value from Value(a) -/// And a Value is returned. -public func <*> (f : Result VB>, a : Result) -> Result { - switch (a, f) { - case let (.Error(l), _): - return .Error(l) - case let (.Value(_), .Error(m)): - return .Error(m) - case let (.Value(r), .Value(g)): - return Result.Value(g(r)) - } -} - -/// Monadic `bind`. Given an Result, and a function from VA -> Result, -/// applies the function `f` if `a` is Value, otherwise the function is ignored and an Error -/// with the Error value from `a` is returned. -public func >>- (a : Result, f : VA -> Result) -> Result { - switch a { - case let .Error(l): - return .Error(l) - case let .Value(r): - return f(r) - } -} From 9c00406b5c03cc355f88aace01dbe6c9178e1b28 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 16 Jul 2015 20:50:38 -0600 Subject: [PATCH 15/48] Add SwiftCheck --- Cartfile.private | 1 + Cartfile.resolved | 1 + 2 files changed, 2 insertions(+) diff --git a/Cartfile.private b/Cartfile.private index 024a97a..bfa565f 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,3 @@ github "typelift/Operadics" +github "typelift/SwiftCheck" "swift-develop" diff --git a/Cartfile.resolved b/Cartfile.resolved index 38c4267..17ef485 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1,2 @@ github "typelift/Operadics" "v0.1.2" +github "typelift/SwiftCheck" "676b8eba5f567d41a307bae57a6de1d868db3bf0" From 3cbc2f8db2cc5183aa4eea5cbf281177728e53e5 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 16 Jul 2015 20:50:50 -0600 Subject: [PATCH 16/48] isLeft/isRight as properties --- Swiftx/Either.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 55854e0..a2cd29b 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -41,7 +41,7 @@ public enum Either { } /// Determines if this Either value is a Left. - public func isLeft() -> Bool { + public var isLeft : Bool { switch self { case Left(_): return true @@ -51,7 +51,7 @@ public enum Either { } /// Determines if this Either value is a Right. - public func isRight() -> Bool { + public var isRight : Bool { switch self { case Left(_): return false @@ -68,7 +68,7 @@ public func <^> (f : RA -> RB, a : Either) -> Either { case let .Left(l): return .Left(l) case let .Right(r): - return Either.Right(f(r)) + return .Right(f(r)) } } @@ -82,7 +82,7 @@ public func <*> (f : Either RB>, a : Either) -> Eithe case let (.Right(_), .Left(m)): return .Left(m) case let (.Right(r), .Right(g)): - return Either.Right(g(r)) + return .Right(g(r)) } } From ec12e370ca9c2f1aabb94098664c32c860f4c063 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 16 Jul 2015 20:50:59 -0600 Subject: [PATCH 17/48] Add Either tests --- EitherSpec.swift | 84 +++++++++++++++++++++++ Swiftx.xcodeproj/project.pbxproj | 114 +++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 EitherSpec.swift diff --git a/EitherSpec.swift b/EitherSpec.swift new file mode 100644 index 0000000..a5478ec --- /dev/null +++ b/EitherSpec.swift @@ -0,0 +1,84 @@ +// +// EitherSpec.swift +// Swiftx +// +// Created by Robert Widmann on 7/16/15. +// Copyright © 2015 TypeLift. All rights reserved. +// + +import Swiftx +import XCTest +import SwiftCheck + +extension Either where L : Arbitrary, R : Arbitrary { + static var arbitrary : Gen> { + return Gen.oneOf([ + Either.Left <^> L.arbitrary, + Either.Right <^> R.arbitrary, + ]) + } + + static func shrink(e : Either) -> [Either] { + switch e { + case .Left(let x): + return L.shrink(x).map(Either.Left) + case .Right(let x): + return R.shrink(x).map(Either.Right) + } + } +} + +// Heterogenous equality +public func == (lhs : Either, rhs : Either) -> Bool { + switch (lhs, rhs) { + case let (.Left(l), .Left(r)) where l == r: + return true + default: + return false + } +} + +public func == (lhs : Either, rhs : Either) -> Bool { + switch (lhs, rhs) { + case let (.Right(l), .Right(r)) where l == r: + return true + default: + return false + } +} + +class EitherSpec : XCTestCase { + func testProperties() { + property("isLeft behaves") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in + return e.isLeft == e.fold(true, f: const(false)) + } + + property("isRight behaves") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in + return e.isRight == e.fold(false, f: const(true)) + } + + property("either is equivalent to explicit case analysis") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in + return forAll { (f : ArrowOf) in + let s : String + switch e { + case .Left(let x): + s = f.getArrow(x) + case .Right(let x): + s = f.getArrow(x) + } + return e.either(onLeft: f.getArrow, onRight: f.getArrow) == s + } + } + + property("flatMap preserves .Left") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in + return forAll { (f : ArrowOf) in + switch e { + case .Left(_): + return e.flatMap(Either.Right • f.getArrow) == e + case .Right(_): + return Discard() + } + } + } + } +} diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 661fb23..1d5374f 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -9,6 +9,10 @@ /* Begin PBXBuildFile section */ 822A5FBD1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; 822A5FBE1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; + 82E51B401B589D55003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */; }; + 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; }; + 82E51B451B589DEB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B441B589DEB003CA361 /* EitherSpec.swift */; }; + 82E51B461B589DEB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B441B589DEB003CA361 /* EitherSpec.swift */; }; 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; @@ -35,6 +39,48 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 82E51B361B589D43003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 844FCC8D198B320500EB242A; + remoteInfo = SwiftCheck; + }; + 82E51B381B589D43003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 844FCC98198B320500EB242A; + remoteInfo = SwiftCheckTests; + }; + 82E51B3A1B589D43003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 84DF75F81B0BD54600C912B0; + remoteInfo = "SwiftCheck-iOS"; + }; + 82E51B3C1B589D43003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 84DF76021B0BD54600C912B0; + remoteInfo = "SwiftCheck-iOSTests"; + }; + 82E51B3E1B589D4F003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 84DF75F71B0BD54600C912B0; + remoteInfo = "SwiftCheck-iOS"; + }; + 82E51B411B589D5B003CA361 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 844FCC8C198B320500EB242A; + remoteInfo = SwiftCheck; + }; 84A88C961A70BD71003D53CF /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 84A88C801A70BD71003D53CF /* Project object */; @@ -76,6 +122,8 @@ /* Begin PBXFileReference section */ 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; }; + 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCheck.xcodeproj; path = ../SwiftCheck/SwiftCheck.xcodeproj; sourceTree = ""; }; + 82E51B441B589DEB003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EitherSpec.swift; sourceTree = ""; }; 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; @@ -105,6 +153,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */, 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -120,6 +169,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 82E51B401B589D55003CA361 /* SwiftCheck.framework in Frameworks */, 84DF76731B0BDE0A00C912B0 /* Swiftx.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -127,6 +177,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 82E51B301B589D43003CA361 /* Products */ = { + isa = PBXGroup; + children = ( + 82E51B371B589D43003CA361 /* SwiftCheck.framework */, + 82E51B391B589D43003CA361 /* SwiftCheckTests.xctest */, + 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */, + 82E51B3D1B589D43003CA361 /* SwiftCheck-iOSTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; 84A88C7F1A70BD71003D53CF = { isa = PBXGroup; children = ( @@ -192,6 +253,7 @@ isa = PBXGroup; children = ( 84A88D341A70BF4C003D53CF /* SectionTests.swift */, + 82E51B441B589DEB003CA361 /* EitherSpec.swift */, 84A88D371A70BF4F003D53CF /* Supporting Files */, ); name = SwiftxTests; @@ -200,6 +262,7 @@ 84A88D371A70BF4F003D53CF /* Supporting Files */ = { isa = PBXGroup; children = ( + 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */, 84A88D331A70BF4C003D53CF /* Info.plist */, ); name = "Supporting Files"; @@ -257,6 +320,7 @@ buildRules = ( ); dependencies = ( + 82E51B421B589D5B003CA361 /* PBXTargetDependency */, 84A88C971A70BD71003D53CF /* PBXTargetDependency */, ); name = SwiftxTests; @@ -294,6 +358,7 @@ buildRules = ( ); dependencies = ( + 82E51B3F1B589D4F003CA361 /* PBXTargetDependency */, 84DF76751B0BDE0A00C912B0 /* PBXTargetDependency */, ); name = "Swiftx-iOSTests"; @@ -335,6 +400,12 @@ mainGroup = 84A88C7F1A70BD71003D53CF; productRefGroup = 84A88C8A1A70BD71003D53CF /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 82E51B301B589D43003CA361 /* Products */; + ProjectRef = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + }, + ); projectRoot = ""; targets = ( 84A88C881A70BD71003D53CF /* Swiftx */, @@ -345,6 +416,37 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + 82E51B371B589D43003CA361 /* SwiftCheck.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftCheck.framework; + remoteRef = 82E51B361B589D43003CA361 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 82E51B391B589D43003CA361 /* SwiftCheckTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SwiftCheckTests.xctest; + remoteRef = 82E51B381B589D43003CA361 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftCheck.framework; + remoteRef = 82E51B3A1B589D43003CA361 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 82E51B3D1B589D43003CA361 /* SwiftCheck-iOSTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "SwiftCheck-iOSTests.xctest"; + remoteRef = 82E51B3C1B589D43003CA361 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXResourcesBuildPhase section */ 84A88C871A70BD71003D53CF /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -398,6 +500,7 @@ buildActionMask = 2147483647; files = ( 84A88D451A70BFA6003D53CF /* SectionTests.swift in Sources */, + 82E51B451B589DEB003CA361 /* EitherSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -421,12 +524,23 @@ buildActionMask = 2147483647; files = ( 84DF768C1B0BDE9700C912B0 /* SectionTests.swift in Sources */, + 82E51B461B589DEB003CA361 /* EitherSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 82E51B3F1B589D4F003CA361 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "SwiftCheck-iOS"; + targetProxy = 82E51B3E1B589D4F003CA361 /* PBXContainerItemProxy */; + }; + 82E51B421B589D5B003CA361 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SwiftCheck; + targetProxy = 82E51B411B589D5B003CA361 /* PBXContainerItemProxy */; + }; 84A88C971A70BD71003D53CF /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 84A88C881A70BD71003D53CF /* Swiftx */; From 29d3497adde83ad78ee76bba0eba9eb08991b1e0 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Thu, 16 Jul 2015 21:18:54 -0600 Subject: [PATCH 18/48] Convert tests to swiftcheck properties --- SwiftxTests/SectionTests.swift | 265 ++++++++++++++++----------------- 1 file changed, 129 insertions(+), 136 deletions(-) diff --git a/SwiftxTests/SectionTests.swift b/SwiftxTests/SectionTests.swift index 77ce2a4..bcca1ea 100644 --- a/SwiftxTests/SectionTests.swift +++ b/SwiftxTests/SectionTests.swift @@ -8,29 +8,141 @@ import XCTest import Swiftx +import SwiftCheck class SectionTests: XCTestCase { - func testShiftRightSections() { - let s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - let t = s.map({ x in x >> 2 }) - - XCTAssertTrue(s.map(>>2) == t, "") - - let t2 = s.map({ x in 2 >> x }) - XCTAssertTrue(s.map(2>>) == t2, "") + func testBitShiftProperties() { + property("") <- forAll { (x : ArrayOf>, sh : Positive) in + let xs = x.getArray.map { min(63, $0.getPositive) } + let shft = min(63, sh.getPositive) + return + xs.map(>>shft) == xs.map { x in x >> shft } + ^&&^ + xs.map(shft>>) == xs.map { x in shft >> x } + } + + property("") <- forAll { (x : ArrayOf>, sh : Positive) in + let xs = x.getArray.map { min(63, $0.getPositive) } + let shft = min(63, sh.getPositive) + return + xs.map(<, i : Int) in + let xs = x.getArray + return + xs.map(+i) == xs.map { $0 + i } + ^&&^ + xs.map(i+) == xs.map { i + $0 } + } + + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in + let xs = x.getArray.map { $0.getNonZero } + let i = ix.getNonZero + return + xs.map(%i) == xs.map { $0 % i } + ^&&^ + xs.map(i%) == xs.map { i % $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(*i) == xs.map { $0 * i } + ^&&^ + xs.map(i*) == xs.map { i * $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(+i) == xs.map { $0 + i } + ^&&^ + xs.map(i+) == xs.map { i + $0 } + } + + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in + let xs = x.getArray.map { $0.getPositive } + let d = ix.getNonZero + + return + xs.map(/d) == xs.map { $0 / d } + ^&&^ + xs.map(d/) == xs.map { d / $0 } + } + + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in + let xs = x.getArray.map { $0.getNonZero } + let i = ix.getNonZero + return + xs.map(&-i) == xs.map { $0 &- i } + ^&&^ + xs.map(i&-) == xs.map { i &- $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(&*i) == xs.map { $0 &* i } + ^&&^ + xs.map(i&*) == xs.map { i &* $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(&+i) == xs.map { $0 &+ i } + ^&&^ + xs.map(i&+) == xs.map { i &+ $0 } + } + } + + func testLogicalSections() { + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(^i) == xs.map { $0 ^ i } + ^&&^ + xs.map(i^) == xs.map { i ^ $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(|i) == xs.map { $0 | i } + ^&&^ + xs.map(i|) == xs.map { i | $0 } + } } - func testShiftLeftSections() { - let s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - let t = s.map({ x in x << 2 }) - - XCTAssertTrue(s.map(<<2) == t, "") - - let t2 = s.map({ x in 2 << x }) - XCTAssertTrue(s.map(2<<) == t2, "") + func testEqualitySections() { + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return + xs.map(==i) == xs.map { $0 == i } + ^&&^ + xs.map(i==) == xs.map { i == $0 } + } + + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray + return xs.map(!=i) == xs.map { $0 != i } + } + } + + func testNilCoalescingSections() { + property("") <- forAll { (x : ArrayOf, i : Int) in + let xs = x.getArray.map(Optional.Some).flatMap(Optional.shrink) + return xs.map(??i) == xs.map { $0 ?? i } + } } - func testClosedIntervalSections() { + + func testIntervalProperties() { let s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] let t = s.map({ x in x...11 }) @@ -49,123 +161,4 @@ class SectionTests: XCTestCase { let t2 = s.map({ x in 0.. Date: Sat, 18 Jul 2015 15:19:02 -0600 Subject: [PATCH 19/48] Use submodules --- .gitmodules | 6 ++++++ Carthage/Checkouts/Operadics | 1 + Carthage/Checkouts/SwiftCheck | 1 + 3 files changed, 8 insertions(+) create mode 100644 .gitmodules create mode 160000 Carthage/Checkouts/Operadics create mode 160000 Carthage/Checkouts/SwiftCheck diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1ac5cc8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "Carthage/Checkouts/SwiftCheck"] + path = Carthage/Checkouts/SwiftCheck + url = https://github.com/typelift/SwiftCheck.git +[submodule "Carthage/Checkouts/Operadics"] + path = Carthage/Checkouts/Operadics + url = https://github.com/typelift/Operadics.git diff --git a/Carthage/Checkouts/Operadics b/Carthage/Checkouts/Operadics new file mode 160000 index 0000000..0cf4ba9 --- /dev/null +++ b/Carthage/Checkouts/Operadics @@ -0,0 +1 @@ +Subproject commit 0cf4ba90af565214643542a1dc9a7193a3eb5720 diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck new file mode 160000 index 0000000..676b8eb --- /dev/null +++ b/Carthage/Checkouts/SwiftCheck @@ -0,0 +1 @@ +Subproject commit 676b8eba5f567d41a307bae57a6de1d868db3bf0 From 3b020d30db69a7824e07e4f6f0feb1e3f884edca Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 18 Jul 2015 15:25:18 -0600 Subject: [PATCH 20/48] Move tests into the proper directories --- Swiftx.xcodeproj/project.pbxproj | 24 +++++++++---------- .../EitherSpec.swift | 0 .../{SectionTests.swift => SectionSpec.swift} | 0 3 files changed, 12 insertions(+), 12 deletions(-) rename EitherSpec.swift => SwiftxTests/EitherSpec.swift (100%) rename SwiftxTests/{SectionTests.swift => SectionSpec.swift} (100%) diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 1d5374f..5db108a 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -11,8 +11,8 @@ 822A5FBE1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; 82E51B401B589D55003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */; }; 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; }; - 82E51B451B589DEB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B441B589DEB003CA361 /* EitherSpec.swift */; }; - 82E51B461B589DEB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B441B589DEB003CA361 /* EitherSpec.swift */; }; + 82E51B5C1B5AFBAA003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; + 82E51B5D1B5AFBAB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; @@ -25,7 +25,7 @@ 84A88D031A70BDB9003D53CF /* Sections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF31A70BDB9003D53CF /* Sections.swift */; }; 84A88D081A70BDDA003D53CF /* Swiftx.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88D071A70BDDA003D53CF /* Swiftx.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84A88D351A70BF4C003D53CF /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 84A88D331A70BF4C003D53CF /* Info.plist */; }; - 84A88D451A70BFA6003D53CF /* SectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88D341A70BF4C003D53CF /* SectionTests.swift */; }; + 84A88D451A70BFA6003D53CF /* SectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88D341A70BF4C003D53CF /* SectionSpec.swift */; }; 84DF76731B0BDE0A00C912B0 /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; }; 84DF76811B0BDE4E00C912B0 /* Swiftx.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88D071A70BDDA003D53CF /* Swiftx.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84DF76821B0BDE5400C912B0 /* Combinators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CED1A70BDB9003D53CF /* Combinators.swift */; }; @@ -35,7 +35,7 @@ 84DF76891B0BDE5400C912B0 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CE91A70BDB9003D53CF /* Array.swift */; }; 84DF768A1B0BDE5400C912B0 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CEC1A70BDB9003D53CF /* Error.swift */; }; 84DF768B1B0BDE5400C912B0 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88CF11A70BDB9003D53CF /* Optional.swift */; }; - 84DF768C1B0BDE9700C912B0 /* SectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88D341A70BF4C003D53CF /* SectionTests.swift */; }; + 84DF768C1B0BDE9700C912B0 /* SectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88D341A70BF4C003D53CF /* SectionSpec.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -123,7 +123,7 @@ /* Begin PBXFileReference section */ 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; }; 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCheck.xcodeproj; path = ../SwiftCheck/SwiftCheck.xcodeproj; sourceTree = ""; }; - 82E51B441B589DEB003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EitherSpec.swift; sourceTree = ""; }; + 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EitherSpec.swift; path = SwiftxTests/EitherSpec.swift; sourceTree = ""; }; 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; @@ -136,7 +136,7 @@ 84A88CF31A70BDB9003D53CF /* Sections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sections.swift; sourceTree = ""; }; 84A88D071A70BDDA003D53CF /* Swiftx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Swiftx.h; path = Swiftx/Swiftx.h; sourceTree = ""; }; 84A88D331A70BF4C003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SwiftxTests/Info.plist; sourceTree = ""; }; - 84A88D341A70BF4C003D53CF /* SectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SectionTests.swift; path = SwiftxTests/SectionTests.swift; sourceTree = ""; }; + 84A88D341A70BF4C003D53CF /* SectionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SectionSpec.swift; path = SwiftxTests/SectionSpec.swift; sourceTree = ""; }; 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84DF76721B0BDE0A00C912B0 /* Swiftx-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Swiftx-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -252,8 +252,8 @@ 84A88D2E1A70BF0A003D53CF /* SwiftxTests */ = { isa = PBXGroup; children = ( - 84A88D341A70BF4C003D53CF /* SectionTests.swift */, - 82E51B441B589DEB003CA361 /* EitherSpec.swift */, + 84A88D341A70BF4C003D53CF /* SectionSpec.swift */, + 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */, 84A88D371A70BF4F003D53CF /* Supporting Files */, ); name = SwiftxTests; @@ -499,8 +499,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 84A88D451A70BFA6003D53CF /* SectionTests.swift in Sources */, - 82E51B451B589DEB003CA361 /* EitherSpec.swift in Sources */, + 84A88D451A70BFA6003D53CF /* SectionSpec.swift in Sources */, + 82E51B5D1B5AFBAB003CA361 /* EitherSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -523,8 +523,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 84DF768C1B0BDE9700C912B0 /* SectionTests.swift in Sources */, - 82E51B461B589DEB003CA361 /* EitherSpec.swift in Sources */, + 84DF768C1B0BDE9700C912B0 /* SectionSpec.swift in Sources */, + 82E51B5C1B5AFBAA003CA361 /* EitherSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/EitherSpec.swift b/SwiftxTests/EitherSpec.swift similarity index 100% rename from EitherSpec.swift rename to SwiftxTests/EitherSpec.swift diff --git a/SwiftxTests/SectionTests.swift b/SwiftxTests/SectionSpec.swift similarity index 100% rename from SwiftxTests/SectionTests.swift rename to SwiftxTests/SectionSpec.swift From 2dacb27da1977a5f6b50db375fce6b1e0233c9cd Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 18 Jul 2015 17:22:48 -0600 Subject: [PATCH 21/48] Copy SwiftCheck to testing bundle --- Swiftx.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 5db108a..f9c6e08 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; }; 82E51B5C1B5AFBAA003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; 82E51B5D1B5AFBAB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; + 82E51B5F1B5B16AD003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 82E51B601B5B16B5003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; @@ -104,6 +106,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 82E51B601B5B16B5003CA361 /* SwiftCheck.framework in CopyFiles */, 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; @@ -114,6 +117,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 82E51B5F1B5B16AD003CA361 /* SwiftCheck.framework in CopyFiles */, 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; From d28676afc3d9ac6b7afd4df949f3cc2e8e48441d Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 20 Jul 2015 09:32:19 -0600 Subject: [PATCH 22/48] What the hell, Xcode? --- Swiftx.xcodeproj/project.pbxproj | 86 ++++++++++++++++---------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index f9c6e08..49c0da5 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -9,12 +9,12 @@ /* Begin PBXBuildFile section */ 822A5FBD1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; 822A5FBE1B4CC78A00F48B0B /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 822A5FBC1B4CC78A00F48B0B /* Operators.swift */; }; - 82E51B401B589D55003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */; }; - 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; }; 82E51B5C1B5AFBAA003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; 82E51B5D1B5AFBAB003CA361 /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */; }; - 82E51B5F1B5B16AD003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 82E51B601B5B16B5003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B371B589D43003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 82E51B941B5D4B9D003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B8B1B5D4B8B003CA361 /* SwiftCheck.framework */; }; + 82E51B961B5D4BA3003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B8F1B5D4B8B003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 82E51B971B5D4BAC003CA361 /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82E51B8B1B5D4B8B003CA361 /* SwiftCheck.framework */; }; + 82E51B981B5D4BAE003CA361 /* SwiftCheck.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 82E51B8B1B5D4B8B003CA361 /* SwiftCheck.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88C891A70BD71003D53CF /* Swiftx.framework */; }; @@ -41,44 +41,44 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 82E51B361B589D43003CA361 /* PBXContainerItemProxy */ = { + 82E51B8A1B5D4B8B003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 2; remoteGlobalIDString = 844FCC8D198B320500EB242A; remoteInfo = SwiftCheck; }; - 82E51B381B589D43003CA361 /* PBXContainerItemProxy */ = { + 82E51B8C1B5D4B8B003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 2; remoteGlobalIDString = 844FCC98198B320500EB242A; remoteInfo = SwiftCheckTests; }; - 82E51B3A1B589D43003CA361 /* PBXContainerItemProxy */ = { + 82E51B8E1B5D4B8B003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 2; remoteGlobalIDString = 84DF75F81B0BD54600C912B0; remoteInfo = "SwiftCheck-iOS"; }; - 82E51B3C1B589D43003CA361 /* PBXContainerItemProxy */ = { + 82E51B901B5D4B8B003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 2; remoteGlobalIDString = 84DF76021B0BD54600C912B0; remoteInfo = "SwiftCheck-iOSTests"; }; - 82E51B3E1B589D4F003CA361 /* PBXContainerItemProxy */ = { + 82E51B921B5D4B99003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 1; remoteGlobalIDString = 84DF75F71B0BD54600C912B0; remoteInfo = "SwiftCheck-iOS"; }; - 82E51B411B589D5B003CA361 /* PBXContainerItemProxy */ = { + 82E51B9A1B5D4BB9003CA361 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + containerPortal = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; proxyType = 1; remoteGlobalIDString = 844FCC8C198B320500EB242A; remoteInfo = SwiftCheck; @@ -106,7 +106,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 82E51B601B5B16B5003CA361 /* SwiftCheck.framework in CopyFiles */, + 82E51B961B5D4BA3003CA361 /* SwiftCheck.framework in CopyFiles */, 841408BD1B1A89AD00BA2B6C /* Swiftx.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; @@ -117,7 +117,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 82E51B5F1B5B16AD003CA361 /* SwiftCheck.framework in CopyFiles */, + 82E51B981B5D4BAE003CA361 /* SwiftCheck.framework in CopyFiles */, 8480AB371A7B232A00C6162D /* Swiftx.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; @@ -126,8 +126,8 @@ /* Begin PBXFileReference section */ 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; }; - 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCheck.xcodeproj; path = ../SwiftCheck/SwiftCheck.xcodeproj; sourceTree = ""; }; 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EitherSpec.swift; path = SwiftxTests/EitherSpec.swift; sourceTree = ""; }; + 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCheck.xcodeproj; path = Carthage/Checkouts/SwiftCheck/SwiftCheck.xcodeproj; sourceTree = ""; }; 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; @@ -157,7 +157,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 82E51B431B589D5F003CA361 /* SwiftCheck.framework in Frameworks */, + 82E51B971B5D4BAC003CA361 /* SwiftCheck.framework in Frameworks */, 84A88C951A70BD71003D53CF /* Swiftx.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -173,7 +173,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 82E51B401B589D55003CA361 /* SwiftCheck.framework in Frameworks */, + 82E51B941B5D4B9D003CA361 /* SwiftCheck.framework in Frameworks */, 84DF76731B0BDE0A00C912B0 /* Swiftx.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -181,13 +181,13 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 82E51B301B589D43003CA361 /* Products */ = { + 82E51B841B5D4B8B003CA361 /* Products */ = { isa = PBXGroup; children = ( - 82E51B371B589D43003CA361 /* SwiftCheck.framework */, - 82E51B391B589D43003CA361 /* SwiftCheckTests.xctest */, - 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */, - 82E51B3D1B589D43003CA361 /* SwiftCheck-iOSTests.xctest */, + 82E51B8B1B5D4B8B003CA361 /* SwiftCheck.framework */, + 82E51B8D1B5D4B8B003CA361 /* SwiftCheckTests.xctest */, + 82E51B8F1B5D4B8B003CA361 /* SwiftCheck.framework */, + 82E51B911B5D4B8B003CA361 /* SwiftCheck-iOSTests.xctest */, ); name = Products; sourceTree = ""; @@ -195,6 +195,7 @@ 84A88C7F1A70BD71003D53CF = { isa = PBXGroup; children = ( + 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */, 84A88D071A70BDDA003D53CF /* Swiftx.h */, 84A88CE81A70BDB9003D53CF /* Swiftx */, 84A88D2E1A70BF0A003D53CF /* SwiftxTests */, @@ -266,7 +267,6 @@ 84A88D371A70BF4F003D53CF /* Supporting Files */ = { isa = PBXGroup; children = ( - 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */, 84A88D331A70BF4C003D53CF /* Info.plist */, ); name = "Supporting Files"; @@ -324,7 +324,7 @@ buildRules = ( ); dependencies = ( - 82E51B421B589D5B003CA361 /* PBXTargetDependency */, + 82E51B9B1B5D4BB9003CA361 /* PBXTargetDependency */, 84A88C971A70BD71003D53CF /* PBXTargetDependency */, ); name = SwiftxTests; @@ -362,7 +362,7 @@ buildRules = ( ); dependencies = ( - 82E51B3F1B589D4F003CA361 /* PBXTargetDependency */, + 82E51B931B5D4B99003CA361 /* PBXTargetDependency */, 84DF76751B0BDE0A00C912B0 /* PBXTargetDependency */, ); name = "Swiftx-iOSTests"; @@ -406,8 +406,8 @@ projectDirPath = ""; projectReferences = ( { - ProductGroup = 82E51B301B589D43003CA361 /* Products */; - ProjectRef = 82E51B2F1B589D43003CA361 /* SwiftCheck.xcodeproj */; + ProductGroup = 82E51B841B5D4B8B003CA361 /* Products */; + ProjectRef = 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */; }, ); projectRoot = ""; @@ -421,32 +421,32 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 82E51B371B589D43003CA361 /* SwiftCheck.framework */ = { + 82E51B8B1B5D4B8B003CA361 /* SwiftCheck.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = SwiftCheck.framework; - remoteRef = 82E51B361B589D43003CA361 /* PBXContainerItemProxy */; + remoteRef = 82E51B8A1B5D4B8B003CA361 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 82E51B391B589D43003CA361 /* SwiftCheckTests.xctest */ = { + 82E51B8D1B5D4B8B003CA361 /* SwiftCheckTests.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; path = SwiftCheckTests.xctest; - remoteRef = 82E51B381B589D43003CA361 /* PBXContainerItemProxy */; + remoteRef = 82E51B8C1B5D4B8B003CA361 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 82E51B3B1B589D43003CA361 /* SwiftCheck.framework */ = { + 82E51B8F1B5D4B8B003CA361 /* SwiftCheck.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = SwiftCheck.framework; - remoteRef = 82E51B3A1B589D43003CA361 /* PBXContainerItemProxy */; + remoteRef = 82E51B8E1B5D4B8B003CA361 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 82E51B3D1B589D43003CA361 /* SwiftCheck-iOSTests.xctest */ = { + 82E51B911B5D4B8B003CA361 /* SwiftCheck-iOSTests.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; path = "SwiftCheck-iOSTests.xctest"; - remoteRef = 82E51B3C1B589D43003CA361 /* PBXContainerItemProxy */; + remoteRef = 82E51B901B5D4B8B003CA361 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -535,15 +535,15 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 82E51B3F1B589D4F003CA361 /* PBXTargetDependency */ = { + 82E51B931B5D4B99003CA361 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = "SwiftCheck-iOS"; - targetProxy = 82E51B3E1B589D4F003CA361 /* PBXContainerItemProxy */; + targetProxy = 82E51B921B5D4B99003CA361 /* PBXContainerItemProxy */; }; - 82E51B421B589D5B003CA361 /* PBXTargetDependency */ = { + 82E51B9B1B5D4BB9003CA361 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = SwiftCheck; - targetProxy = 82E51B411B589D5B003CA361 /* PBXContainerItemProxy */; + targetProxy = 82E51B9A1B5D4BB9003CA361 /* PBXContainerItemProxy */; }; 84A88C971A70BD71003D53CF /* PBXTargetDependency */ = { isa = PBXTargetDependency; From 313e4fb1f6565c5aadca105528db7b082126e4c0 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 25 Jul 2015 01:10:44 -0600 Subject: [PATCH 23/48] ++SwiftCheck --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 17ef485..6bb1bb2 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "676b8eba5f567d41a307bae57a6de1d868db3bf0" +github "typelift/SwiftCheck" "4f74ca9d81faf822e10d81c9b22aa27478c64986" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index 676b8eb..4f74ca9 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit 676b8eba5f567d41a307bae57a6de1d868db3bf0 +Subproject commit 4f74ca9d81faf822e10d81c9b22aa27478c64986 From b31bfa4aa8d604c7c9fbd068994644660604bc23 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:04:45 -0600 Subject: [PATCH 24/48] Update to beta 5 --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- Swiftx/Array.swift | 20 +++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 6bb1bb2..08c6e57 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "4f74ca9d81faf822e10d81c9b22aa27478c64986" +github "typelift/SwiftCheck" "39dbec2ccd9334baade439d6eb93c7ea2e437537" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index 4f74ca9..39dbec2 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit 4f74ca9d81faf822e10d81c9b22aa27478c64986 +Subproject commit 39dbec2ccd9334baade439d6eb93c7ea2e437537 diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index 9d25933..9f531a7 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -8,24 +8,18 @@ /// Fmap | Maps a function over the contents of an array and returns a new array of the resulting /// values. -public func <^> (f : A -> B, a : [A]) -> [B] { - return a.map(f) +public func <^> (f : A -> B, xs : [A]) -> [B] { + return xs.map(f) } -/// Ap | Given an [A -> B] and an [A], returns a [B]. Applies the function at each index in `f` to +/// Ap | Given an [A -> B] and an [A], returns a [B]. Applies the function at each index in `f` to /// every index in `a` and returns the results in a new array. -public func <*> (f : [(A -> B)], a : [A]) -> [B] { - var re = [B]() - for g in f { - for h in a { - re.append(g(h)) - } - } - return re +public func <*> (fs : [(A -> B)], xs : [A]) -> [B] { + return fs.flatMap(Array.map(xs)) } /// Bind | Given an [A], and a function from A -> [B], applies the function `f` to every element in /// [A] and returns the result. -public func >>- (a : [A], f : A -> [B]) -> [B] { - return a.flatMap(f) +public func >>- (xs : [A], f : A -> [B]) -> [B] { + return xs.flatMap(f) } From 2458e1f2f9917a60f2e03eb5a0bcc91c1bb7cfe1 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:17:00 -0600 Subject: [PATCH 25/48] Redo docs for ArrayExt --- Swiftx/Array.swift | 14 ++++++++------ Swiftx/Optional.swift | 6 +----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index 9f531a7..501f99d 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -6,20 +6,22 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// Fmap | Maps a function over the contents of an array and returns a new array of the resulting -/// values. +/// Fmap | Returns a new list of elements obtained by applying the given function to the entirety of +/// the given list of elements in order. public func <^> (f : A -> B, xs : [A]) -> [B] { return xs.map(f) } -/// Ap | Given an [A -> B] and an [A], returns a [B]. Applies the function at each index in `f` to -/// every index in `a` and returns the results in a new array. +/// Ap | Returns the result of applying each element of the given array of functions to the entirety +/// of the list of elements, repeating until the list of functions has been exhausted. +/// +/// Promotes function application to lists of functions applied to lists of elements. public func <*> (fs : [(A -> B)], xs : [A]) -> [B] { return fs.flatMap(Array.map(xs)) } -/// Bind | Given an [A], and a function from A -> [B], applies the function `f` to every element in -/// [A] and returns the result. +/// Bind | Returns the result of mapping the given function over the given array of elements and +/// concatenating the result. public func >>- (xs : [A], f : A -> [B]) -> [B] { return xs.flatMap(f) } diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 457a8b8..3cccfab 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -20,11 +20,7 @@ public func <^> (f : A -> B, a : A?) -> B? { /// param is None, simply returns None. Otherwise the function taken from Some(f) is applied to the /// value from Some(a) and a Some is returned. public func <*> (f : (A -> B)?, a : A?) -> B? { - if f != nil && a != nil { - return (f!(a!)) - } else { - return .None - } + return f.flatMap(Optional.map(a)) } /// Bind | Given an Optional, and a function from A -> Optional, applies the function `f` if From 6613d0765dc9f6934b499f9c9f3bea294f862884 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:17:24 -0600 Subject: [PATCH 26/48] Simplify Optional functions --- Swiftx/Optional.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 3cccfab..34fca7d 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -9,11 +9,7 @@ /// Fmap | If the Optional is None, ignores the function and returns None. If the Optional is Some, /// applies the function to the Some value and returns the result in a new Some. public func <^> (f : A -> B, a : A?) -> B? { - if let x = a { - return (f(x)) - } else { - return .None - } + return a.map(f) } /// Ap | Given an Optional B> and an Optional, returns an Optional. If the `f` or `a' @@ -26,9 +22,5 @@ public func <*> (f : (A -> B)?, a : A?) -> B? { /// Bind | Given an Optional, and a function from A -> Optional, applies the function `f` if /// `a` is Some, otherwise the function is ignored and None is returned. public func >>- (a : A?, f : A -> B?) -> B? { - if let x = a { - return f(x) - } else { - return .None - } + return a.flatMap(f) } From 9dc6a2419597e5519563cdeb089ad6691b36f740 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:25:46 -0600 Subject: [PATCH 27/48] Fix Optional docs --- Swiftx/Array.swift | 2 +- Swiftx/Optional.swift | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index 501f99d..220c0f0 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -15,7 +15,7 @@ public func <^> (f : A -> B, xs : [A]) -> [B] { /// Ap | Returns the result of applying each element of the given array of functions to the entirety /// of the list of elements, repeating until the list of functions has been exhausted. /// -/// Promotes function application to lists of functions applied to lists of elements. +/// Promotes function application to arrays of functions applied to arrays of elements. public func <*> (fs : [(A -> B)], xs : [A]) -> [B] { return fs.flatMap(Array.map(xs)) } diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 34fca7d..46c3f0a 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -6,21 +6,26 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// Fmap | If the Optional is None, ignores the function and returns None. If the Optional is Some, -/// applies the function to the Some value and returns the result in a new Some. +/// Fmap | If the Optional is `.None`, ignores the function and returns `.None`. Else if the +/// Optional is `.Some`, applies the function to its value and returns the result in a new `.Some`. public func <^> (f : A -> B, a : A?) -> B? { return a.map(f) } -/// Ap | Given an Optional B> and an Optional, returns an Optional. If the `f` or `a' -/// param is None, simply returns None. Otherwise the function taken from Some(f) is applied to the -/// value from Some(a) and a Some is returned. +/// Ap | Returns the result of applying the given Optional function to a given Optional value. If +/// the function and value both exist the result is the function applied to the value. Else the +/// result is `.None`. +/// +/// Promotes function application to an Optional function applied to an Optional value. public func <*> (f : (A -> B)?, a : A?) -> B? { return f.flatMap(Optional.map(a)) } -/// Bind | Given an Optional, and a function from A -> Optional, applies the function `f` if -/// `a` is Some, otherwise the function is ignored and None is returned. +/// Bind | Returns the result of applying a function return an Optional to an Optional value. If +/// the value is `.None` the result of this function is `.None`. If the value is `.Some`, the +/// result is the application of the function to the value contained within. +/// +/// Bind propagates any occurance of `.None` through a computation that may fail at several points. public func >>- (a : A?, f : A -> B?) -> B? { return a.flatMap(f) } From a51e28dcee99d86931465170177f000a3afe645c Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:25:54 -0600 Subject: [PATCH 28/48] Remove false caveat clause --- Swiftx/Error.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Swiftx/Error.swift b/Swiftx/Error.swift index 1b58600..f409f2d 100644 --- a/Swiftx/Error.swift +++ b/Swiftx/Error.swift @@ -22,8 +22,6 @@ public func error(x : String) -> A { /// public func sortBy(cmp : (A, A) -> Bool)(l : [A]) -> [A] { /// return undefined() /// } -/// -/// The same caveat about compilation modes applies to "undefined" as to "error". public func undefined() -> A { return error("Undefined") } From 0912c660854d18e5b4efa82bf67cf1ba8a1873b7 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 8 Aug 2015 13:52:57 -0600 Subject: [PATCH 29/48] Improve Either Docs --- Swiftx/Combinators.swift | 3 +- Swiftx/Either.swift | 67 +++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index 95f3390..b8677b2 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -21,8 +21,7 @@ public func flip(f : ((A, B) -> C), b : B, a : A) -> C { return f(a, b) } -/// Flip a function's arguments and return a function that takes -/// the arguments in flipped order. +/// Flip a function's arguments and return a function that takes the arguments in flipped order. public func flip(f : (A, B) -> C)(b : B, a : A) -> C { return f(a, b) } diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index a2cd29b..91933d7 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -8,29 +8,33 @@ /// The `Either` type represents values with two possibilities: `.Left(L)` or `.Right(R)`. /// -/// The Either type is sometimes used to represent a value which is either correct or an error; by -/// convention, the Left constructor is used to hold an error value and the Right constructor is -/// used to hold a correct value (mnemonic: "right" also means "correct"). +/// The `Either` type is right-biased by convention. That is, the `.Left` constructor is used to +/// hold errors and is generally ignored and left to propagate in combinators involving `Either`, +/// while `.Right` is used to hold a "correct" value - one that can be operated on further. +/// +/// (mnemonic: "Right" also means "Correct"). public enum Either { case Left(L) case Right(R) - /// Much like the ?? operator for Optional types, takes a value and a function, - /// and if the Either is Left, returns the value, otherwise maps the function over - /// the value in Right and returns that value. + /// Much like the ?? operator for Optional types, takes a value and a function, and if the + /// reciever is `.Left`, returns the value, otherwise maps the function over the value in + /// `.Right` and returns that value. public func fold(value : B, f : R -> B) -> B { return either(onLeft: const(value), onRight: f); } - /// Named function for `>>-`. If the Either is Left, simply returns + /// Named function for `>>-`. If the `Either` is Left, simply returns /// a New Left with the value of the receiver. If Right, applies the function `f` /// and returns the result. public func flatMap(f : R -> Either) -> Either { return self >>- f } - /// Case analysis for the Either type. If the value is Left(a), apply the first function to a; - /// if it is Right(b), apply the second function to b. + /// Case analysis for the `Either` type. + /// + /// If the value is `.Left(a)`, apply the first function to `a`. If it is `.Right(b)`, apply the + /// second function to `b`. public func either(onLeft onLeft : L -> A, onRight : R -> A) -> A { switch self { case let .Left(e): @@ -40,7 +44,7 @@ public enum Either { } } - /// Determines if this Either value is a Left. + /// Determines if this `Either` value is a Left. public var isLeft : Bool { switch self { case Left(_): @@ -50,21 +54,22 @@ public enum Either { } } - /// Determines if this Either value is a Right. + /// Determines if this `Either` value is a Right. public var isRight : Bool { switch self { - case Left(_): - return false case Right(_): return true + case Left(_): + return false } } } -/// Fmap | If the Either is Left, ignores the function and returns the Left. If the Either is Right, -/// applies the function to the Right value and returns the result in a new Right. -public func <^> (f : RA -> RB, a : Either) -> Either { - switch a { +/// Fmap | Applies a function to any non-error value contained in the given Either. +/// +/// If the `Either` is `.Left`, the given function is ignored and result of this function is `.Left`. +public func <^> (f : RA -> RB, e : Either) -> Either { + switch e { case let .Left(l): return .Left(l) case let .Right(r): @@ -72,23 +77,27 @@ public func <^> (f : RA -> RB, a : Either) -> Either { } } -/// Ap | Given an Either RB> and an Either, returns an Either. If the `f` or -/// `a' param is a Left, simply returns a Left with the same value. Otherwise the function taken -/// from Right(f) is applied to the value from Right(a) and a Right is returned. -public func <*> (f : Either RB>, a : Either) -> Either { - switch (a, f) { +/// Ap | Given an `Either` containing an error value or a function, applies the function to any non- +/// error values contained in the given either. +/// +/// If the `Either` containing the function is `.Left` the result of this function is `.Left`. Else +/// the result of this function is the result of `fmap`ing the function over the given Either. +/// +/// Promotes function application to sums of values and functions applied to sums of values. +public func <*> (f : Either RB>, e : Either) -> Either { + switch (f, e) { case let (.Left(l), _): return .Left(l) - case let (.Right(_), .Left(m)): - return .Left(m) - case let (.Right(r), .Right(g)): - return .Right(g(r)) + case let (.Right(f), r): + return f <^> r } } -/// Bind | Given an Either, and a function from RA -> Either, applies the function `f` -/// if `a` is Right, otherwise the function is ignored and a Left with the Left value from `a` is -/// returned. +/// Bind | Applies a function to any non-error value contained in the given Either. +/// +/// If the `Either` is `.Left`, the given function is ignored and the result of this function is +/// `.Left`. Else the reuslt of this function is the application of the function to the value +/// contained in teh Either. public func >>- (a : Either, f : RA -> Either) -> Either { switch a { case let .Left(l): From ec5dce6e7c301d9c038b409142f37763d64a5857 Mon Sep 17 00:00:00 2001 From: Alexander Altman Date: Wed, 19 Aug 2015 20:17:51 -0700 Subject: [PATCH 30/48] Update `.gitignore` --- .gitignore | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5a57e75..f2ee158 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,42 @@ -# Xcode +### https://raw.github.com/github/gitignore/5d5de5306f9d4d47f6a3643410febcd9db6b145c/Global/OSX.gitignore + .DS_Store -build/* +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### https://raw.github.com/github/gitignore/5d5de5306f9d4d47f6a3643410febcd9db6b145c/Global/Xcode.gitignore + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData + +## Various settings *.pbxuser !default.pbxuser *.mode1v3 @@ -10,13 +46,43 @@ build/* *.perspectivev3 !default.perspectivev3 xcuserdata + +## Other *.xccheckout *.moved-aside +*.xcuserstate + + +### https://raw.github.com/github/gitignore/5d5de5306f9d4d47f6a3643410febcd9db6b145c/Swift.gitignore + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ DerivedData + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata + +## Other +*.xccheckout +*.moved-aside +*.xcuserstate +*.xcscmblueprint + +## Obj-C/Swift specific *.hmap *.ipa -*.xcuserstate -Carthage/ # CocoaPods # @@ -26,3 +92,11 @@ Carthage/ # # Pods/ +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + + From 71330d067542172ed9b1d768f35538726e53c0cf Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 25 Aug 2015 19:00:03 -0400 Subject: [PATCH 31/48] ++SwiftCheck --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- .../xcshareddata/Swiftx.xcscmblueprint | 42 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint diff --git a/Cartfile.resolved b/Cartfile.resolved index 08c6e57..b359e5f 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "39dbec2ccd9334baade439d6eb93c7ea2e437537" +github "typelift/SwiftCheck" "afeaf31740b9761d52459721d2934afd4a25ba63" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index 39dbec2..afeaf31 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit 39dbec2ccd9334baade439d6eb93c7ea2e437537 +Subproject commit afeaf31740b9761d52459721d2934afd4a25ba63 diff --git a/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint b/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint new file mode 100644 index 0000000..8aceb35 --- /dev/null +++ b/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint @@ -0,0 +1,42 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "3F7B0726EE5826699845B3907BCC122BD128DE11", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "53964F28C4CCA0826677C9F951DD3F64C20326C4" : 0, + "B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 0, + "3F7B0726EE5826699845B3907BCC122BD128DE11" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "E8A98424-9D59-4A01-A4DD-45A7868C25DC", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Swiftx\/Carthage\/Checkouts\/SwiftCheck\/", + "B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Swiftx\/Carthage\/Checkouts\/SwiftCheck\/Carthage\/Checkouts\/Operadics\/", + "3F7B0726EE5826699845B3907BCC122BD128DE11" : "Swiftx" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "Swiftx", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Swiftx.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Swiftx.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "3F7B0726EE5826699845B3907BCC122BD128DE11" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/SwiftCheck.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "53964F28C4CCA0826677C9F951DD3F64C20326C4" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A" + } + ] +} \ No newline at end of file From 3b2e1a737b744f9594c202c5385d667b8ab0551f Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 25 Aug 2015 19:00:12 -0400 Subject: [PATCH 32/48] Update to beta 6 --- Swiftx/Array.swift | 2 +- Swiftx/Optional.swift | 2 +- Swiftx/Sections.swift | 16 ---------------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Swiftx/Array.swift b/Swiftx/Array.swift index 220c0f0..296301c 100644 --- a/Swiftx/Array.swift +++ b/Swiftx/Array.swift @@ -17,7 +17,7 @@ public func <^> (f : A -> B, xs : [A]) -> [B] { /// /// Promotes function application to arrays of functions applied to arrays of elements. public func <*> (fs : [(A -> B)], xs : [A]) -> [B] { - return fs.flatMap(Array.map(xs)) + return fs.flatMap({ xs.map($0) }) } /// Bind | Returns the result of mapping the given function over the given array of elements and diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 46c3f0a..6188129 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -18,7 +18,7 @@ public func <^> (f : A -> B, a : A?) -> B? { /// /// Promotes function application to an Optional function applied to an Optional value. public func <*> (f : (A -> B)?, a : A?) -> B? { - return f.flatMap(Optional.map(a)) + return f.flatMap({ a.map($0) }) } /// Bind | Returns the result of applying a function return an Optional to an Optional value. If diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index 82aa92b..8d1c484 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -1126,14 +1126,6 @@ public prefix func ==(rhs : String.UTF16View.Index) -> String.UTF16View.Index -> return { lhs in lhs == rhs } } -public postfix func == (lhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { - return { rhs in lhs == rhs } -} - -public prefix func == (rhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { - return { lhs in lhs == rhs } -} - public prefix func ==(rhs : Float) -> Float -> Bool { return { lhs in lhs == rhs } } @@ -1514,14 +1506,6 @@ public prefix func !=(rhs : Int) -> Int -> Bool { return { lhs in lhs != rhs } } -public postfix func != (lhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { - return { rhs in lhs != rhs } -} - -public prefix func != (rhs : FilterCollectionIndex) -> FilterCollectionIndex -> Bool { - return { lhs in lhs != rhs } -} - public prefix func !=(rhs : Float) -> Float -> Bool { return { lhs in lhs != rhs } } From 99728fd291881cc55d9d3cc49998464a4ceb6d0f Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 25 Aug 2015 19:01:19 -0400 Subject: [PATCH 33/48] Ignore Swiftx.xcscmblueprint --- .gitignore | 1 + .../xcshareddata/Swiftx.xcscmblueprint | 42 ------------------- 2 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint diff --git a/.gitignore b/.gitignore index 5a57e75..4da0414 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData *.hmap *.ipa *.xcuserstate +*.xcscmblueprint Carthage/ # CocoaPods diff --git a/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint b/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint deleted file mode 100644 index 8aceb35..0000000 --- a/Swiftx.xcodeproj/project.xcworkspace/xcshareddata/Swiftx.xcscmblueprint +++ /dev/null @@ -1,42 +0,0 @@ -{ - "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "3F7B0726EE5826699845B3907BCC122BD128DE11", - "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { - - }, - "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { - "53964F28C4CCA0826677C9F951DD3F64C20326C4" : 0, - "B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 0, - "3F7B0726EE5826699845B3907BCC122BD128DE11" : 0 - }, - "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "E8A98424-9D59-4A01-A4DD-45A7868C25DC", - "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { - "53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Swiftx\/Carthage\/Checkouts\/SwiftCheck\/", - "B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Swiftx\/Carthage\/Checkouts\/SwiftCheck\/Carthage\/Checkouts\/Operadics\/", - "3F7B0726EE5826699845B3907BCC122BD128DE11" : "Swiftx" - }, - "DVTSourceControlWorkspaceBlueprintNameKey" : "Swiftx", - "DVTSourceControlWorkspaceBlueprintVersion" : 204, - "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Swiftx.xcodeproj", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Swiftx.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "3F7B0726EE5826699845B3907BCC122BD128DE11" - }, - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/SwiftCheck.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "53964F28C4CCA0826677C9F951DD3F64C20326C4" - }, - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A" - }, - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A" - } - ] -} \ No newline at end of file From 5b6c8b5d81ee3624407f498aeb5427ff31722f74 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 25 Aug 2015 19:05:39 -0400 Subject: [PATCH 34/48] Add LazyFilterIndex sections --- Swiftx/Sections.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index 8d1c484..d0fdb00 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -1126,6 +1126,14 @@ public prefix func ==(rhs : String.UTF16View.Index) -> String.UTF16View.Index -> return { lhs in lhs == rhs } } +public postfix func == (lhs : LazyFilterIndex) -> LazyFilterIndex -> Bool { + return { rhs in lhs == rhs } +} + +public prefix func == (rhs : LazyFilterIndex) -> LazyFilterIndex -> Bool { + return { lhs in lhs == rhs } +} + public prefix func ==(rhs : Float) -> Float -> Bool { return { lhs in lhs == rhs } } @@ -1506,6 +1514,14 @@ public prefix func !=(rhs : Int) -> Int -> Bool { return { lhs in lhs != rhs } } +public postfix func != (lhs : LazyFilterIndex) -> LazyFilterIndex -> Bool { + return { rhs in lhs != rhs } +} + +public prefix func != (rhs : LazyFilterIndex) -> LazyFilterIndex -> Bool { + return { lhs in lhs != rhs } +} + public prefix func !=(rhs : Float) -> Float -> Bool { return { lhs in lhs != rhs } } From dc91f020b9241f180a7a6d1a5fce96e2fdc77a4b Mon Sep 17 00:00:00 2001 From: Alexander Altman Date: Fri, 28 Aug 2015 15:19:17 -0700 Subject: [PATCH 35/48] Bring formatting up to scratch. --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- Swiftx.xcodeproj/project.pbxproj | 20 +++---- Swiftx/Either.swift | 18 +++--- Swiftx/Error.swift | 2 +- Swiftx/Nothing.swift | 2 +- Swiftx/Optional.swift | 2 +- Swiftx/Sections.swift | 90 +++++++++++++++--------------- SwiftxTests/EitherSpec.swift | 10 ++-- SwiftxTests/SectionSpec.swift | 94 ++++++++++++++++---------------- 10 files changed, 121 insertions(+), 121 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index b359e5f..e010680 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "afeaf31740b9761d52459721d2934afd4a25ba63" +github "typelift/SwiftCheck" "d45d7023fa93c51292079c159ff18aa0c1cf5269" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index afeaf31..d45d702 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit afeaf31740b9761d52459721d2934afd4a25ba63 +Subproject commit d45d7023fa93c51292079c159ff18aa0c1cf5269 diff --git a/Swiftx.xcodeproj/project.pbxproj b/Swiftx.xcodeproj/project.pbxproj index 49c0da5..922c647 100644 --- a/Swiftx.xcodeproj/project.pbxproj +++ b/Swiftx.xcodeproj/project.pbxproj @@ -125,22 +125,22 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; }; - 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EitherSpec.swift; path = SwiftxTests/EitherSpec.swift; sourceTree = ""; }; + 822A5FBC1B4CC78A00F48B0B /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Operators.swift; path = Carthage/Checkouts/Operadics/Operators.swift; sourceTree = SOURCE_ROOT; usesTabs = 1; }; + 82E51B591B5AFBA7003CA361 /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EitherSpec.swift; path = SwiftxTests/EitherSpec.swift; sourceTree = ""; usesTabs = 1; }; 82E51B831B5D4B8B003CA361 /* SwiftCheck.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCheck.xcodeproj; path = Carthage/Checkouts/SwiftCheck/SwiftCheck.xcodeproj; sourceTree = ""; }; 84A88C891A70BD71003D53CF /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88C941A70BD71003D53CF /* SwiftxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; + 84A88CE91A70BDB9003D53CF /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; usesTabs = 1; }; 84A88CEB1A70BDB9003D53CF /* Either.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = ""; usesTabs = 1; }; - 84A88CEC1A70BDB9003D53CF /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = ""; }; - 84A88CED1A70BDB9003D53CF /* Combinators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinators.swift; sourceTree = ""; }; + 84A88CEC1A70BDB9003D53CF /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = ""; usesTabs = 1; }; + 84A88CED1A70BDB9003D53CF /* Combinators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinators.swift; sourceTree = ""; usesTabs = 1; }; 84A88CEE1A70BDB9003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 84A88CEF1A70BDB9003D53CF /* Nothing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nothing.swift; sourceTree = ""; }; - 84A88CF11A70BDB9003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; }; - 84A88CF31A70BDB9003D53CF /* Sections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sections.swift; sourceTree = ""; }; - 84A88D071A70BDDA003D53CF /* Swiftx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Swiftx.h; path = Swiftx/Swiftx.h; sourceTree = ""; }; + 84A88CEF1A70BDB9003D53CF /* Nothing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nothing.swift; sourceTree = ""; usesTabs = 1; }; + 84A88CF11A70BDB9003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; usesTabs = 1; }; + 84A88CF31A70BDB9003D53CF /* Sections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sections.swift; sourceTree = ""; usesTabs = 1; }; + 84A88D071A70BDDA003D53CF /* Swiftx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Swiftx.h; path = Swiftx/Swiftx.h; sourceTree = ""; usesTabs = 1; }; 84A88D331A70BF4C003D53CF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SwiftxTests/Info.plist; sourceTree = ""; }; - 84A88D341A70BF4C003D53CF /* SectionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SectionSpec.swift; path = SwiftxTests/SectionSpec.swift; sourceTree = ""; }; + 84A88D341A70BF4C003D53CF /* SectionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SectionSpec.swift; path = SwiftxTests/SectionSpec.swift; sourceTree = ""; usesTabs = 1; }; 84DF76681B0BDE0A00C912B0 /* Swiftx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Swiftx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84DF76721B0BDE0A00C912B0 /* Swiftx-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Swiftx-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ diff --git a/Swiftx/Either.swift b/Swiftx/Either.swift index 91933d7..faf470f 100644 --- a/Swiftx/Either.swift +++ b/Swiftx/Either.swift @@ -17,8 +17,8 @@ public enum Either { case Left(L) case Right(R) - /// Much like the ?? operator for Optional types, takes a value and a function, and if the - /// reciever is `.Left`, returns the value, otherwise maps the function over the value in + /// Much like the ?? operator for Optional types, takes a value and a function, and if the + /// reciever is `.Left`, returns the value, otherwise maps the function over the value in /// `.Right` and returns that value. public func fold(value : B, f : R -> B) -> B { return either(onLeft: const(value), onRight: f); @@ -31,7 +31,7 @@ public enum Either { return self >>- f } - /// Case analysis for the `Either` type. + /// Case analysis for the `Either` type. /// /// If the value is `.Left(a)`, apply the first function to `a`. If it is `.Right(b)`, apply the /// second function to `b`. @@ -65,7 +65,7 @@ public enum Either { } } -/// Fmap | Applies a function to any non-error value contained in the given Either. +/// Fmap | Applies a function to any non-error value contained in the given Either. /// /// If the `Either` is `.Left`, the given function is ignored and result of this function is `.Left`. public func <^> (f : RA -> RB, e : Either) -> Either { @@ -78,11 +78,11 @@ public func <^> (f : RA -> RB, e : Either) -> Either { } /// Ap | Given an `Either` containing an error value or a function, applies the function to any non- -/// error values contained in the given either. +/// error values contained in the given either. /// -/// If the `Either` containing the function is `.Left` the result of this function is `.Left`. Else +/// If the `Either` containing the function is `.Left` the result of this function is `.Left`. Else /// the result of this function is the result of `fmap`ing the function over the given Either. -/// +/// /// Promotes function application to sums of values and functions applied to sums of values. public func <*> (f : Either RB>, e : Either) -> Either { switch (f, e) { @@ -93,9 +93,9 @@ public func <*> (f : Either RB>, e : Either) -> Eithe } } -/// Bind | Applies a function to any non-error value contained in the given Either. +/// Bind | Applies a function to any non-error value contained in the given Either. /// -/// If the `Either` is `.Left`, the given function is ignored and the result of this function is +/// If the `Either` is `.Left`, the given function is ignored and the result of this function is /// `.Left`. Else the reuslt of this function is the application of the function to the value /// contained in teh Either. public func >>- (a : Either, f : RA -> Either) -> Either { diff --git a/Swiftx/Error.swift b/Swiftx/Error.swift index f409f2d..003ff73 100644 --- a/Swiftx/Error.swift +++ b/Swiftx/Error.swift @@ -8,7 +8,7 @@ /// Immediately terminates the program with an error message. public func error(x : String) -> A { - fatalError(x) + fatalError(x) } /// A special case of error. diff --git a/Swiftx/Nothing.swift b/Swiftx/Nothing.swift index 2f967c6..d528233 100644 --- a/Swiftx/Nothing.swift +++ b/Swiftx/Nothing.swift @@ -6,6 +6,6 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// An enum that represents Nothing, otherwise called Bottom or Absurdity. It is the type from +/// An enum that represents Nothing, otherwise called Bottom or Absurdity. It is the type from /// which no information can be drawn and no instance may be constructed. public enum Nothing { } diff --git a/Swiftx/Optional.swift b/Swiftx/Optional.swift index 6188129..54b0548 100644 --- a/Swiftx/Optional.swift +++ b/Swiftx/Optional.swift @@ -6,7 +6,7 @@ // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // -/// Fmap | If the Optional is `.None`, ignores the function and returns `.None`. Else if the +/// Fmap | If the Optional is `.None`, ignores the function and returns `.None`. Else if the /// Optional is `.Some`, applies the function to its value and returns the result in a new `.Some`. public func <^> (f : A -> B, a : A?) -> B? { return a.map(f) diff --git a/Swiftx/Sections.swift b/Swiftx/Sections.swift index d0fdb00..b42eef8 100644 --- a/Swiftx/Sections.swift +++ b/Swiftx/Sections.swift @@ -510,13 +510,13 @@ public postfix func % (lhs : T) -> T -> T { } #if os(OSX) -public prefix func %(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { lhs in lhs % rhs } -} + public prefix func %(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { lhs in lhs % rhs } + } -public postfix func %(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { rhs in lhs % rhs } -} + public postfix func %(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { rhs in lhs % rhs } + } #endif public prefix func %(rhs : Double) -> Double -> Double { @@ -627,13 +627,13 @@ public postfix func * (lhs : T) -> T -> T { } #if os(OSX) -public prefix func *(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { lhs in lhs * rhs } -} + public prefix func *(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { lhs in lhs * rhs } + } -public postfix func *(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { rhs in lhs * rhs } -} + public postfix func *(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { rhs in lhs * rhs } + } #endif public prefix func *(rhs : Double) -> Double -> Double { @@ -744,13 +744,13 @@ public postfix func + (lhs : T) -> T -> T { } #if os(OSX) -public prefix func +(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { lhs in lhs + rhs } -} + public prefix func +(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { lhs in lhs + rhs } + } -public postfix func +(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { rhs in lhs + rhs } -} + public postfix func +(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { rhs in lhs + rhs } + } #endif public prefix func +(rhs : Double) -> Double -> Double { @@ -884,9 +884,9 @@ public postfix func - (lhs : T) -> T -> T { } #if os(OSX) -public postfix func -(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { rhs in lhs - rhs } -} + public postfix func -(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { rhs in lhs - rhs } + } #endif public postfix func -(lhs : Double) -> Double -> Double { @@ -981,13 +981,13 @@ public postfix func / (lhs : T) -> T -> T { } #if os(OSX) -public prefix func /(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { lhs in lhs / rhs } -} + public prefix func /(rhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { lhs in lhs / rhs } + } -public postfix func /(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { - return { rhs in lhs / rhs } -} + public postfix func /(lhs : Swift.Float80) -> Swift.Float80 -> Swift.Float80 { + return { rhs in lhs / rhs } + } #endif public prefix func /(rhs : Double) -> Double -> Double { @@ -1183,13 +1183,13 @@ public prefix func ==(rhs : Character) -> Character -> Bool { } #if os(OSX) -public postfix func ==(lhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { rhs in lhs == rhs } -} + public postfix func ==(lhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { rhs in lhs == rhs } + } -public prefix func ==(rhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { lhs in lhs == rhs } -} + public prefix func ==(rhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { lhs in lhs == rhs } + } #endif public postfix func ==(lhs : FloatingPointClassification) -> FloatingPointClassification -> Bool { @@ -1571,13 +1571,13 @@ public prefix func !=(rhs : Character) -> Character -> Bool { } #if os(OSX) -public postfix func !=(lhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { rhs in lhs != rhs } -} + public postfix func !=(lhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { rhs in lhs != rhs } + } -public prefix func !=(rhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { lhs in lhs != rhs } -} + public prefix func !=(rhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { lhs in lhs != rhs } + } #endif public postfix func !=(lhs : FloatingPointClassification) -> FloatingPointClassification -> Bool { @@ -2090,9 +2090,9 @@ public prefix func >(rhs : String) -> String -> Bool { } #if os(OSX) -public prefix func >(rhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { lhs in lhs > rhs } -} + public prefix func >(rhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { lhs in lhs > rhs } + } #endif public prefix func >(rhs : Double) -> Double -> Bool { @@ -2199,9 +2199,9 @@ public postfix func <(lhs : String) -> String -> Bool { } #if os(OSX) -public postfix func <(lhs : Swift.Float80) -> Swift.Float80 -> Bool { - return { rhs in lhs < rhs } -} + public postfix func <(lhs : Swift.Float80) -> Swift.Float80 -> Bool { + return { rhs in lhs < rhs } + } #endif public postfix func <(lhs : Double) -> Double -> Bool { diff --git a/SwiftxTests/EitherSpec.swift b/SwiftxTests/EitherSpec.swift index a5478ec..9579ed7 100644 --- a/SwiftxTests/EitherSpec.swift +++ b/SwiftxTests/EitherSpec.swift @@ -15,9 +15,9 @@ extension Either where L : Arbitrary, R : Arbitrary { return Gen.oneOf([ Either.Left <^> L.arbitrary, Either.Right <^> R.arbitrary, - ]) + ]) } - + static func shrink(e : Either) -> [Either] { switch e { case .Left(let x): @@ -52,11 +52,11 @@ class EitherSpec : XCTestCase { property("isLeft behaves") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in return e.isLeft == e.fold(true, f: const(false)) } - + property("isRight behaves") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in return e.isRight == e.fold(false, f: const(true)) } - + property("either is equivalent to explicit case analysis") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in return forAll { (f : ArrowOf) in let s : String @@ -69,7 +69,7 @@ class EitherSpec : XCTestCase { return e.either(onLeft: f.getArrow, onRight: f.getArrow) == s } } - + property("flatMap preserves .Left") <- forAllShrink(Either.arbitrary, shrinker: Either.shrink) { e in return forAll { (f : ArrowOf) in switch e { diff --git a/SwiftxTests/SectionSpec.swift b/SwiftxTests/SectionSpec.swift index bcca1ea..7d5a9fb 100644 --- a/SwiftxTests/SectionSpec.swift +++ b/SwiftxTests/SectionSpec.swift @@ -17,117 +17,117 @@ class SectionTests: XCTestCase { let shft = min(63, sh.getPositive) return xs.map(>>shft) == xs.map { x in x >> shft } - ^&&^ - xs.map(shft>>) == xs.map { x in shft >> x } + ^&&^ + xs.map(shft>>) == xs.map { x in shft >> x } } - + property("") <- forAll { (x : ArrayOf>, sh : Positive) in let xs = x.getArray.map { min(63, $0.getPositive) } let shft = min(63, sh.getPositive) return xs.map(<, i : Int) in let xs = x.getArray return xs.map(+i) == xs.map { $0 + i } - ^&&^ - xs.map(i+) == xs.map { i + $0 } + ^&&^ + xs.map(i+) == xs.map { i + $0 } } - + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in let xs = x.getArray.map { $0.getNonZero } let i = ix.getNonZero return xs.map(%i) == xs.map { $0 % i } - ^&&^ - xs.map(i%) == xs.map { i % $0 } + ^&&^ + xs.map(i%) == xs.map { i % $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(*i) == xs.map { $0 * i } - ^&&^ - xs.map(i*) == xs.map { i * $0 } + ^&&^ + xs.map(i*) == xs.map { i * $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(+i) == xs.map { $0 + i } - ^&&^ - xs.map(i+) == xs.map { i + $0 } + ^&&^ + xs.map(i+) == xs.map { i + $0 } } - + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in let xs = x.getArray.map { $0.getPositive } let d = ix.getNonZero - + return xs.map(/d) == xs.map { $0 / d } - ^&&^ - xs.map(d/) == xs.map { d / $0 } + ^&&^ + xs.map(d/) == xs.map { d / $0 } } - + property("") <- forAll { (x : ArrayOf>, ix : NonZero) in let xs = x.getArray.map { $0.getNonZero } let i = ix.getNonZero return xs.map(&-i) == xs.map { $0 &- i } - ^&&^ - xs.map(i&-) == xs.map { i &- $0 } + ^&&^ + xs.map(i&-) == xs.map { i &- $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(&*i) == xs.map { $0 &* i } - ^&&^ - xs.map(i&*) == xs.map { i &* $0 } + ^&&^ + xs.map(i&*) == xs.map { i &* $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(&+i) == xs.map { $0 &+ i } - ^&&^ - xs.map(i&+) == xs.map { i &+ $0 } + ^&&^ + xs.map(i&+) == xs.map { i &+ $0 } } } - + func testLogicalSections() { property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(^i) == xs.map { $0 ^ i } - ^&&^ - xs.map(i^) == xs.map { i ^ $0 } + ^&&^ + xs.map(i^) == xs.map { i ^ $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(|i) == xs.map { $0 | i } - ^&&^ - xs.map(i|) == xs.map { i | $0 } + ^&&^ + xs.map(i|) == xs.map { i | $0 } } } - + func testEqualitySections() { property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(==i) == xs.map { $0 == i } - ^&&^ - xs.map(i==) == xs.map { i == $0 } + ^&&^ + xs.map(i==) == xs.map { i == $0 } } - + property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(!=i) == xs.map { $0 != i } @@ -140,24 +140,24 @@ class SectionTests: XCTestCase { return xs.map(??i) == xs.map { $0 ?? i } } } - - + + func testIntervalProperties() { let s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] let t = s.map({ x in x...11 }) - + XCTAssertTrue(s.map(...11) == t, "") - + let t2 = s.map({ x in 0...x }) XCTAssertTrue(s.map(0...) == t2, "") } - + func testOpenIntervalSections() { let s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] let t = s.map({ x in x..<11 }) - + XCTAssertTrue(s.map(..<11) == t, "") - + let t2 = s.map({ x in 0.. Date: Fri, 28 Aug 2015 17:39:58 -0700 Subject: [PATCH 36/48] Misc fixes --- Swiftx/Swiftx.h | 10 ------- SwiftxTests/EitherSpec.swift | 2 +- SwiftxTests/SectionSpec.swift | 52 +++++++++++++++++------------------ 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/Swiftx/Swiftx.h b/Swiftx/Swiftx.h index 0231761..a5fb5c0 100644 --- a/Swiftx/Swiftx.h +++ b/Swiftx/Swiftx.h @@ -6,14 +6,4 @@ // Copyright (c) 2015 TypeLift. All rights reserved. // -#import - -//! Project version number for Swiftx. -FOUNDATION_EXPORT double SwiftxVersionNumber; - -//! Project version string for Swiftx. -FOUNDATION_EXPORT const unsigned char SwiftxVersionString[]; - // In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/SwiftxTests/EitherSpec.swift b/SwiftxTests/EitherSpec.swift index 9579ed7..002a0f3 100644 --- a/SwiftxTests/EitherSpec.swift +++ b/SwiftxTests/EitherSpec.swift @@ -15,7 +15,7 @@ extension Either where L : Arbitrary, R : Arbitrary { return Gen.oneOf([ Either.Left <^> L.arbitrary, Either.Right <^> R.arbitrary, - ]) + ]) } static func shrink(e : Either) -> [Either] { diff --git a/SwiftxTests/SectionSpec.swift b/SwiftxTests/SectionSpec.swift index 7d5a9fb..77fc602 100644 --- a/SwiftxTests/SectionSpec.swift +++ b/SwiftxTests/SectionSpec.swift @@ -17,8 +17,8 @@ class SectionTests: XCTestCase { let shft = min(63, sh.getPositive) return xs.map(>>shft) == xs.map { x in x >> shft } - ^&&^ - xs.map(shft>>) == xs.map { x in shft >> x } + ^&&^ + xs.map(shft>>) == xs.map { x in shft >> x } } property("") <- forAll { (x : ArrayOf>, sh : Positive) in @@ -26,8 +26,8 @@ class SectionTests: XCTestCase { let shft = min(63, sh.getPositive) return xs.map(<>, ix : NonZero) in @@ -45,24 +45,24 @@ class SectionTests: XCTestCase { let i = ix.getNonZero return xs.map(%i) == xs.map { $0 % i } - ^&&^ - xs.map(i%) == xs.map { i % $0 } + ^&&^ + xs.map(i%) == xs.map { i % $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(*i) == xs.map { $0 * i } - ^&&^ - xs.map(i*) == xs.map { i * $0 } + ^&&^ + xs.map(i*) == xs.map { i * $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(+i) == xs.map { $0 + i } - ^&&^ - xs.map(i+) == xs.map { i + $0 } + ^&&^ + xs.map(i+) == xs.map { i + $0 } } property("") <- forAll { (x : ArrayOf>, ix : NonZero) in @@ -71,8 +71,8 @@ class SectionTests: XCTestCase { return xs.map(/d) == xs.map { $0 / d } - ^&&^ - xs.map(d/) == xs.map { d / $0 } + ^&&^ + xs.map(d/) == xs.map { d / $0 } } property("") <- forAll { (x : ArrayOf>, ix : NonZero) in @@ -80,24 +80,24 @@ class SectionTests: XCTestCase { let i = ix.getNonZero return xs.map(&-i) == xs.map { $0 &- i } - ^&&^ - xs.map(i&-) == xs.map { i &- $0 } + ^&&^ + xs.map(i&-) == xs.map { i &- $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(&*i) == xs.map { $0 &* i } - ^&&^ - xs.map(i&*) == xs.map { i &* $0 } + ^&&^ + xs.map(i&*) == xs.map { i &* $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(&+i) == xs.map { $0 &+ i } - ^&&^ - xs.map(i&+) == xs.map { i &+ $0 } + ^&&^ + xs.map(i&+) == xs.map { i &+ $0 } } } @@ -106,16 +106,16 @@ class SectionTests: XCTestCase { let xs = x.getArray return xs.map(^i) == xs.map { $0 ^ i } - ^&&^ - xs.map(i^) == xs.map { i ^ $0 } + ^&&^ + xs.map(i^) == xs.map { i ^ $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in let xs = x.getArray return xs.map(|i) == xs.map { $0 | i } - ^&&^ - xs.map(i|) == xs.map { i | $0 } + ^&&^ + xs.map(i|) == xs.map { i | $0 } } } @@ -124,8 +124,8 @@ class SectionTests: XCTestCase { let xs = x.getArray return xs.map(==i) == xs.map { $0 == i } - ^&&^ - xs.map(i==) == xs.map { i == $0 } + ^&&^ + xs.map(i==) == xs.map { i == $0 } } property("") <- forAll { (x : ArrayOf, i : Int) in From cac9990cd539ba5c76c502097fc9be0ef346cfee Mon Sep 17 00:00:00 2001 From: Daniel Asher Date: Sun, 6 Sep 2015 20:45:24 +0100 Subject: [PATCH 37/48] make `fix` polymorphic in two type variables and add an exception enable version `fixt` --- Swiftx/Combinators.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index b8677b2..4f01afc 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -88,10 +88,16 @@ public func |> (a : A, f : A -> B) -> B { /// point at which further application of x to a function is the same x. /// /// x = f(x) -public func fix(f : ((A -> A) -> A -> A)) -> A -> A { +public func fix(f : (A -> B) -> A -> B) -> A -> B { return { x in f(fix(f))(x) } } +/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first +/// point at which further application of x to a function is the same x. +/// fixt is the exception enabled version of fix. +public func fixt(f : (A throws -> B) -> A throws -> B) -> A throws -> B { + return { x in try f(fixt(f))(x) } +} /// On | Applies the function on its right to both its arguments, then applies the function on its /// left to the result of both prior applications. /// From f04f7db053f5a9be788d45b91910cd0bbf2364e1 Mon Sep 17 00:00:00 2001 From: Daniel Asher Date: Sun, 6 Sep 2015 21:17:09 +0100 Subject: [PATCH 38/48] /// line added above `public func fixt` comment line /// added above `fixt` definition. --- Swiftx/Combinators.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index 4f01afc..ec4c66b 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -94,7 +94,8 @@ public func fix(f : (A -> B) -> A -> B) -> A -> B { /// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first /// point at which further application of x to a function is the same x. -/// fixt is the exception enabled version of fix. +/// fixt is the exception-enabled version of fix. +/// public func fixt(f : (A throws -> B) -> A throws -> B) -> A throws -> B { return { x in try f(fixt(f))(x) } } From e24d631c615ee819ccbeeedebbeff5e66193bf81 Mon Sep 17 00:00:00 2001 From: Daniel Asher Date: Sun, 6 Sep 2015 21:22:02 +0100 Subject: [PATCH 39/48] add markdown to comment before `fixt` --- Swiftx/Combinators.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index ec4c66b..5d70602 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -94,8 +94,8 @@ public func fix(f : (A -> B) -> A -> B) -> A -> B { /// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first /// point at which further application of x to a function is the same x. -/// fixt is the exception-enabled version of fix. /// +/// `fixt` is the exception-enabled version of fix. public func fixt(f : (A throws -> B) -> A throws -> B) -> A throws -> B { return { x in try f(fixt(f))(x) } } From 7c8e9a21c76bb968fb0054cc6dcf4c341a349f17 Mon Sep 17 00:00:00 2001 From: Daniel Asher Date: Sun, 6 Sep 2015 21:39:22 +0100 Subject: [PATCH 40/48] reformulate `fixt` to use `rethrows` correctly fixt now uses rethrows correctly --- Swiftx/Combinators.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swiftx/Combinators.swift b/Swiftx/Combinators.swift index 5d70602..f33212f 100644 --- a/Swiftx/Combinators.swift +++ b/Swiftx/Combinators.swift @@ -96,7 +96,7 @@ public func fix(f : (A -> B) -> A -> B) -> A -> B { /// point at which further application of x to a function is the same x. /// /// `fixt` is the exception-enabled version of fix. -public func fixt(f : (A throws -> B) -> A throws -> B) -> A throws -> B { +public func fixt(f : (A throws -> B) throws -> (A throws -> B)) rethrows -> A throws -> B { return { x in try f(fixt(f))(x) } } /// On | Applies the function on its right to both its arguments, then applies the function on its From e1f948d738dac3d5fa3afc7f214923ab77184182 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 11:04:25 -0400 Subject: [PATCH 41/48] Update dependencies --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index e010680..a5d4d01 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "d45d7023fa93c51292079c159ff18aa0c1cf5269" +github "typelift/SwiftCheck" "354140578a6deab234604e298c76e262ad456f6e" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index d45d702..3541405 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit d45d7023fa93c51292079c159ff18aa0c1cf5269 +Subproject commit 354140578a6deab234604e298c76e262ad456f6e From f89a360526b245729d343faf2cf6b04b19355074 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 16:50:32 -0400 Subject: [PATCH 42/48] Update travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a6f6c8e..8450911 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: beta-xcode6.3 +osx_image: xcode7 script: - xctool -project Swiftx.xcodeproj -scheme Swiftx -sdk macosx ONLY_ACTIVE_ARCH=NO clean build test From feebe37ef1823f2359c3ad77a96cbf7fb2f2dd44 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 16:55:45 -0400 Subject: [PATCH 43/48] ++Dependencies --- Cartfile.resolved | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index a5d4d01..e85b441 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "354140578a6deab234604e298c76e262ad456f6e" +github "typelift/SwiftCheck" "fc5ad9be5944f341c6cb1fd0a0428e032ba5f403" diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index 3541405..fc5ad9b 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit 354140578a6deab234604e298c76e262ad456f6e +Subproject commit fc5ad9be5944f341c6cb1fd0a0428e032ba5f403 From 240d9b2f84cd3e15f51c12c87f1e13d2c1fe6287 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 16:56:59 -0400 Subject: [PATCH 44/48] Pull submodules too --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8450911..1a28c5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: objective-c -osx_image: xcode7 +osx_image: xcode7 + +install: + - git submodule update -i --recursive script: - xctool -project Swiftx.xcodeproj -scheme Swiftx -sdk macosx ONLY_ACTIVE_ARCH=NO clean build test From 1ad7cbe6711e4fbb6a7f631de24ebd7e2860a1b6 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 16:59:26 -0400 Subject: [PATCH 45/48] Spaces --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1a28c5f..6016e4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: objective-c osx_image: xcode7 install: - - git submodule update -i --recursive + - git submodule update -i --recursive script: - xctool -project Swiftx.xcodeproj -scheme Swiftx -sdk macosx ONLY_ACTIVE_ARCH=NO clean build test From 3183420143603234803932a5d3e5a7b6c905bff1 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 9 Sep 2015 17:06:49 -0400 Subject: [PATCH 46/48] Stay chill on 32 bit devices --- SwiftxTests/SectionSpec.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftxTests/SectionSpec.swift b/SwiftxTests/SectionSpec.swift index 77fc602..ca5d6fe 100644 --- a/SwiftxTests/SectionSpec.swift +++ b/SwiftxTests/SectionSpec.swift @@ -13,8 +13,8 @@ import SwiftCheck class SectionTests: XCTestCase { func testBitShiftProperties() { property("") <- forAll { (x : ArrayOf>, sh : Positive) in - let xs = x.getArray.map { min(63, $0.getPositive) } - let shft = min(63, sh.getPositive) + let xs = x.getArray.map { min(31, $0.getPositive) } + let shft = min(31, sh.getPositive) return xs.map(>>shft) == xs.map { x in x >> shft } ^&&^ @@ -22,8 +22,8 @@ class SectionTests: XCTestCase { } property("") <- forAll { (x : ArrayOf>, sh : Positive) in - let xs = x.getArray.map { min(63, $0.getPositive) } - let shft = min(63, sh.getPositive) + let xs = x.getArray.map { min(31, $0.getPositive) } + let shft = min(31, sh.getPositive) return xs.map(< Date: Sat, 12 Sep 2015 15:10:55 -0400 Subject: [PATCH 47/48] Update dependencies --- Cartfile.private | 2 +- Cartfile.resolved | 4 ++-- Carthage/Checkouts/Operadics | 2 +- Carthage/Checkouts/SwiftCheck | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cartfile.private b/Cartfile.private index bfa565f..dd87e4b 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ github "typelift/Operadics" -github "typelift/SwiftCheck" "swift-develop" +github "typelift/SwiftCheck" diff --git a/Cartfile.resolved b/Cartfile.resolved index e85b441..ba7e4f3 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "typelift/Operadics" "v0.1.2" -github "typelift/SwiftCheck" "fc5ad9be5944f341c6cb1fd0a0428e032ba5f403" +github "typelift/Operadics" "v0.1.3" +github "typelift/SwiftCheck" "v0.3.0" diff --git a/Carthage/Checkouts/Operadics b/Carthage/Checkouts/Operadics index 0cf4ba9..a5897e8 160000 --- a/Carthage/Checkouts/Operadics +++ b/Carthage/Checkouts/Operadics @@ -1 +1 @@ -Subproject commit 0cf4ba90af565214643542a1dc9a7193a3eb5720 +Subproject commit a5897e80a6054c1d4877348977185ec6264bb8fe diff --git a/Carthage/Checkouts/SwiftCheck b/Carthage/Checkouts/SwiftCheck index fc5ad9b..f807431 160000 --- a/Carthage/Checkouts/SwiftCheck +++ b/Carthage/Checkouts/SwiftCheck @@ -1 +1 @@ -Subproject commit fc5ad9be5944f341c6cb1fd0a0428e032ba5f403 +Subproject commit f807431e1925bce5d7ee4075c1d5471969461cae From 7e4e404e5f22308a97acf9490fdbde14592e70da Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 12 Sep 2015 15:15:46 -0400 Subject: [PATCH 48/48] Update build script --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6016e4a..ae4d894 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: objective-c osx_image: xcode7 +before_install: + - gem install xcpretty-travis-formatter --no-rdoc --no-ri --no-document --quiet + install: - git submodule update -i --recursive script: - - xctool -project Swiftx.xcodeproj -scheme Swiftx -sdk macosx ONLY_ACTIVE_ARCH=NO clean build test - - xctool -project Swiftx.xcodeproj -scheme Swiftx-iOS -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO clean build test - + - set -o pipefail && xcodebuild -project Swiftx.xcodeproj -scheme Swiftx -sdk macosx ONLY_ACTIVE_ARCH=NO clean build test | xcpretty -c -f `xcpretty-travis-formatter` + - set -o pipefail && xcodebuild -project Swiftx.xcodeproj -scheme Swiftx-iOS -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO clean build test | xcpretty -c -f `xcpretty-travis-formatter`