Skip to content

Commit 0a2dda8

Browse files
authored
Merge pull request #58 from typelift/swift-develop
Update to Swift 3.0
2 parents 7aeae54 + 26e9c91 commit 0a2dda8

31 files changed

+252
-2908
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Xcode
22
.DS_Store
3+
.build/*
4+
Packages/*
35
build/*
46
*.pbxuser
57
!default.pbxuser

.travis.yml

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
1-
language: objective-c
2-
osx_image: xcode7.3
31
env:
4-
- TEST_CONFIG="RELEASE"
5-
- TEST_CONFIG="PODS"
6-
7-
before_install: true
8-
install: true
9-
script:
10-
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then script/cibuild Swiftx ; fi
11-
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then xcodebuild test -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' ; fi
12-
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then xcodebuild build -scheme Swiftx-watchOS -destination 'platform=watchOS Simulator,name=Apple Watch - 42mm' ; fi
13-
- if [[ "$TEST_CONFIG" == "PODS" ]]; then pod lib lint; fi
14-
2+
global:
3+
- LC_CTYPE=en_US.UTF-8
4+
matrix:
5+
include:
6+
- os: osx
7+
language: objective-c
8+
osx_image: xcode8
9+
before_install:
10+
- git submodule update --init --recursive
11+
script:
12+
# Restore pod build before shipping for 3.0
13+
# - pod lib lint
14+
- carthage build --no-skip-current
15+
- os: osx
16+
language: objective-c
17+
osx_image: xcode8
18+
before_install:
19+
- git submodule update --init --recursive
20+
script:
21+
- set -o pipefail
22+
- xcodebuild test -scheme Swiftx | xcpretty -c
23+
# -- Start iOS --
24+
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
25+
- iOS_DEVICE_NAME="iPad Pro (12.9 inch)"
26+
- iOS_RUNTIME_VERSION="10.0"
27+
# Get simulator identifier for desired device/runtime pair
28+
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
29+
- echo $SIMULATOR_ID
30+
- echo $iOS_DEVICE_NAME
31+
- echo $iOS_RUNTIME_VERSION
32+
# !!!: Start simulator w/ desired device—helps avoid issues w/ Xcode timing out when waiting for simulator to become ready
33+
- open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $SIMULATOR_ID
34+
- xcodebuild test -scheme Swiftx-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
35+
# -- End iOS --
36+
- xcodebuild test -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
37+
- os: linux
38+
language: generic
39+
sudo: required
40+
dist: trusty
41+
before_install:
42+
- git submodule update --init --recursive
43+
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
44+
- wget https://swift.org/builds/swift-3.0-release/ubuntu1404/swift-3.0-RELEASE/swift-3.0-RELEASE-ubuntu14.04.tar.gz
45+
- tar xzf swift-3.0-RELEASE-ubuntu14.04.tar.gz
46+
- export PATH=${PWD}/swift-3.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
47+
script:
48+
- swift build
1549
notifications:
1650
webhooks:
1751
urls:
1852
- https://webhooks.gitter.im/e/1d781e1bcbabade5de35
1953
on_success: always
2054
on_failure: always
2155
on_start: always
56+

Cartfile.private

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
github "typelift/Operadics"
1+
github "typelift/Operadics"
22
github "typelift/SwiftCheck"
33

Cartfile.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "typelift/Operadics" "0.2.0"
2-
github "typelift/SwiftCheck" "v0.6.0"
1+
github "typelift/Operadics" "0.2.2"
2+
github "typelift/SwiftCheck" "v0.7.0"

Carthage/Checkouts/SwiftCheck

Submodule SwiftCheck updated 53 files

Package.swift

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "Swiftx",
5+
targets: [
6+
Target(name: "Swiftx"),
7+
],
8+
dependencies: [
9+
.Package(url: "https://github.com/typelift/Operadics.git", versions: Version(0,2,2)...Version(0,2,2))
10+
]
11+
)
12+
13+
let libSwiftx = Product(name: "Swiftx", type: .Library(.Dynamic), modules: "Swiftx")
14+
products.append(libSwiftx)

Swiftx/Array.swift Sources/Array.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
77
//
88

9+
#if !XCODE_BUILD
10+
import Operadics
11+
#endif
12+
913
/// Fmap | Returns a new list of elements obtained by applying the given function to the entirety of
1014
/// the given list of elements in order.
11-
public func <^> <A, B>(f : A -> B, xs : [A]) -> [B] {
15+
public func <^> <A, B>(f : (A) -> B, xs : [A]) -> [B] {
1216
return xs.map(f)
1317
}
1418

1519
/// Ap | Returns the result of applying each element of the given array of functions to the entirety
1620
/// of the list of elements, repeating until the list of functions has been exhausted.
1721
///
1822
/// Promotes function application to arrays of functions applied to arrays of elements.
19-
public func <*> <A, B>(fs : [(A -> B)], xs : [A]) -> [B] {
23+
public func <*> <A, B>(fs : [((A) -> B)], xs : [A]) -> [B] {
2024
return fs.flatMap({ xs.map($0) })
2125
}
2226

2327
/// Bind | Returns the result of mapping the given function over the given array of elements and
2428
/// concatenating the result.
25-
public func >>- <A, B>(xs : [A], f : A -> [B]) -> [B] {
29+
public func >>- <A, B>(xs : [A], f : (A) -> [B]) -> [B] {
2630
return xs.flatMap(f)
2731
}

Swiftx/Combinators.swift Sources/Combinators.swift

+20-15
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@
66
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
77
//
88

9+
#if !XCODE_BUILD
10+
import Operadics
11+
#endif
12+
913
/// The identity function.
10-
public func identity<A>(a : A) -> A {
14+
public func identity<A>(_ a : A) -> A {
1115
return a
1216
}
1317

1418
/// The constant combinator ignores its second argument and always returns its first argument.
15-
public func const<A, B>(x : A) -> B -> A {
19+
public func const<A, B>(_ x : A) -> (B) -> A {
1620
return { _ in x }
1721
}
1822

1923
/// Flip a function's arguments
20-
public func flip<A, B, C>(f : ((A, B) -> C), _ b : B, _ a : A) -> C {
24+
public func flip<A, B, C>(_ f : ((A, B) -> C), _ b : B, _ a : A) -> C {
2125
return f(a, b)
2226
}
2327

2428
/// Flip a function's arguments and return a curried function that takes
2529
/// the arguments in flipped order.
26-
public func flip<A, B, C>(f : A -> B -> C) -> B -> A -> C {
30+
public func flip<A, B, C>(_ f : @escaping (A) -> (B) -> C) -> (B) -> (A) -> C {
2731
return { b in { a in f(a)(b) } }
2832
}
2933

@@ -32,7 +36,7 @@ public func flip<A, B, C>(f : A -> B -> C) -> B -> A -> C {
3236
/// f : B -> C
3337
/// g : A -> B
3438
/// (f • g)(x) === f(g(x)) : A -> B -> C
35-
public func <A, B, C>(f : B -> C, g : A -> B) -> A -> C {
39+
public func <A, B, C>(f : @escaping (B) -> C, g : @escaping (A) -> B) -> (A) -> C {
3640
return { (a : A) -> C in
3741
return f(g(a))
3842
}
@@ -47,7 +51,7 @@ public func • <A, B, C>(f : B -> C, g : A -> B) -> A -> C {
4751
/// f § g § h § x = f(g(h(x)))
4852
///
4953
/// Key Chord: ⌥ + 6
50-
public func § <A, B>(f : A -> B, a : A) -> B {
54+
public func § <A, B>(f : (A) -> B, a : A) -> B {
5155
return f(a)
5256
}
5357

@@ -59,7 +63,7 @@ public func § <A, B>(f : A -> B, a : A) -> B {
5963
/// f <| g <| h <| x = f (g (h x))
6064
///
6165
/// Acts as a synonym for §.
62-
public func <| <A, B>(f : A -> B, a : A) -> B {
66+
public func <| <A, B>(f : (A) -> B, a : A) -> B {
6367
return f(a)
6468
}
6569

@@ -75,25 +79,26 @@ public func <| <A, B>(f : A -> B, a : A) -> B {
7579
/// 1 |> { $0.advancedBy($0) }
7680
/// |> { $0.advancedBy($0) }
7781
/// |> { $0 * $0 }
78-
public func |> <A, B>(a : A, f : A -> B) -> B {
82+
public func |> <A, B>(a : A, f : (A) -> B) -> B {
7983
return f(a)
8084
}
8185

8286
/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
8387
/// point at which further application of x to a function is the same x.
8488
///
8589
/// x = f(x)
86-
public func fix<A, B>(f : (A -> B) -> A -> B) -> A -> B {
90+
public func fix<A, B>(_ f : @escaping ((A) -> B) -> (A) -> B) -> (A) -> B {
8791
return { x in f(fix(f))(x) }
8892
}
8993

9094
/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
9195
/// point at which further application of x to a function is the same x.
9296
///
9397
/// `fixt` is the exception-enabled version of fix.
94-
public func fixt<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -> A throws -> B {
98+
public func fixt<A, B>(_ f : @escaping ((A) throws -> B) throws -> ((A) throws -> B)) rethrows -> (A) throws -> B {
9599
return { x in try f(fixt(f))(x) }
96100
}
101+
97102
/// On | Applies the function on its right to both its arguments, then applies the function on its
98103
/// left to the result of both prior applications.
99104
///
@@ -103,7 +108,7 @@ public func fixt<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -
103108
///
104109
/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")]
105110
/// let sortedByFirstIndex = arr.sort((<) |*| fst)
106-
public func |*| <A, B, C>(o : B -> B -> C, f : A -> B) -> A -> A -> C {
111+
public func |*| <A, B, C>(o : @escaping (B) -> (B) -> C, f : @escaping (A) -> B) -> (A) -> (A) -> C {
107112
return on(o)(f)
108113
}
109114

@@ -116,27 +121,27 @@ public func |*| <A, B, C>(o : B -> B -> C, f : A -> B) -> A -> A -> C {
116121
///
117122
/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")]
118123
/// let sortedByFirstIndex = arr.sort((<) |*| fst)
119-
public func |*| <A, B, C>(o : (B, B) -> C, f : A -> B) -> A -> A -> C {
124+
public func |*| <A, B, C>(o : @escaping (B, B) -> C, f : @escaping (A) -> B) -> (A) -> (A) -> C {
120125
return on(o)(f)
121126
}
122127

123128
/// On | Applies the function on its right to both its arguments, then applies the function on its
124129
/// left to the result of both prior applications.
125130
///
126131
/// (+) |*| f = { x in { y in f(x) + f(y) } }
127-
public func on<A, B, C>(o : B -> B -> C) -> (A -> B) -> A -> A -> C {
132+
public func on<A, B, C>(_ o : @escaping (B) -> (B) -> C) -> (@escaping (A) -> B) -> (A) -> (A) -> C {
128133
return { f in { x in { y in o(f(x))(f(y)) } } }
129134
}
130135

131136
/// On | Applies the function on its right to both its arguments, then applies the function on its
132137
/// left to the result of both prior applications.
133138
///
134139
/// (+) |*| f = { x, y in f(x) + f(y) }
135-
public func on<A, B, C>(o : (B, B) -> C) -> (A -> B) -> A -> A -> C {
140+
public func on<A, B, C>(_ o : @escaping (B, B) -> C) -> (@escaping (A) -> B) -> (A) -> (A) -> C {
136141
return { f in { x in { y in o(f(x), f(y)) } } }
137142
}
138143

139144
/// Applies a function to an argument until a given predicate returns true.
140-
public func until<A>(p : A -> Bool) -> (A -> A) -> A -> A {
145+
public func until<A>(_ p : @escaping (A) -> Bool) -> (@escaping (A) -> A) -> (A) -> A {
141146
return { f in { x in p(x) ? x : until(p)(f)(f(x)) } }
142147
}

Swiftx/Either.swift Sources/Either.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
77
//
88

9+
#if !XCODE_BUILD
10+
import Operadics
11+
#endif
12+
913
/// The `Either` type represents values with two possibilities: `.Left(L)` or `.Right(R)`.
1014
///
1115
/// The `Either` type is right-biased by convention. That is, the `.Left` constructor is used to
@@ -20,22 +24,22 @@ public enum Either<L, R> {
2024
/// Much like the ?? operator for `Optional` types, takes a value and a function, and if the
2125
/// receiver is `.Left`, returns the value, otherwise maps the function over the value in
2226
/// `.Right` and returns that value.
23-
public func fold<B>(value : B, f : R -> B) -> B {
27+
public func fold<B>(_ value : B, f : (R) -> B) -> B {
2428
return either(onLeft: const(value), onRight: f);
2529
}
2630

2731
/// Named function for `>>-`. If the `Either` is `Left`, simply returns
2832
/// a new `Left` with the value of the receiver. If `Right`, applies the function `f`
2933
/// and returns the result.
30-
public func flatMap<S>(f : R -> Either<L, S>) -> Either<L, S> {
34+
public func flatMap<S>(_ f : (R) -> Either<L, S>) -> Either<L, S> {
3135
return self >>- f
3236
}
3337

3438
/// Case analysis for the `Either` type.
3539
///
3640
/// If the value is `.Left(a)`, apply the first function to `a`. If it is `.Right(b)`, apply the
3741
/// second function to `b`.
38-
public func either<A>(onLeft onLeft : L -> A, onRight : R -> A) -> A {
42+
public func either<A>(onLeft : (L) -> A, onRight : (R) -> A) -> A {
3943
switch self {
4044
case let .Left(e):
4145
return onLeft(e)
@@ -74,7 +78,7 @@ public enum Either<L, R> {
7478
/// Fmap | Applies a function to any non-error value contained in the given `Either`.
7579
///
7680
/// If the `Either` is `.Left`, the given function is ignored and result of this function is `.Left`.
77-
public func <^> <L, RA, RB>(f : RA -> RB, e : Either<L, RA>) -> Either<L, RB> {
81+
public func <^> <L, RA, RB>(f : (RA) -> RB, e : Either<L, RA>) -> Either<L, RB> {
7882
switch e {
7983
case let .Left(l):
8084
return .Left(l)
@@ -90,7 +94,7 @@ public func <^> <L, RA, RB>(f : RA -> RB, e : Either<L, RA>) -> Either<L, RB> {
9094
/// the result of this function is the result of `fmap`ing the function over the given `Either`.
9195
///
9296
/// Promotes function application to sums of values and functions applied to sums of values.
93-
public func <*> <L, RA, RB>(f : Either<L, RA -> RB>, e : Either<L, RA>) -> Either<L, RB> {
97+
public func <*> <L, RA, RB>(f : Either<L, (RA) -> RB>, e : Either<L, RA>) -> Either<L, RB> {
9498
switch (f, e) {
9599
case let (.Left(l), _):
96100
return .Left(l)
@@ -104,7 +108,7 @@ public func <*> <L, RA, RB>(f : Either<L, RA -> RB>, e : Either<L, RA>) -> Eithe
104108
/// If the `Either` is `.Left`, the given function is ignored and the result of this function is
105109
/// `.Left`. Else the result of this function is the application of the function to the value
106110
/// contained in the `Either`.
107-
public func >>- <L, RA, RB>(a : Either<L, RA>, f : RA -> Either<L, RB>) -> Either<L, RB> {
111+
public func >>- <L, RA, RB>(a : Either<L, RA>, f : (RA) -> Either<L, RB>) -> Either<L, RB> {
108112
switch a {
109113
case let .Left(l):
110114
return .Left(l)

Swiftx/Error.swift Sources/Error.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
/// Immediately terminates the program with an error message.
10-
public func error<A>(x : String) -> A {
10+
public func error<A>(_ x : String) -> A {
1111
fatalError(x)
1212
}
1313

File renamed without changes.

Swiftx/Optional.swift Sources/Optional.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
77
//
88

9+
#if !XCODE_BUILD
10+
import Operadics
11+
#endif
12+
913
/// Fmap | If the Optional is `.None`, ignores the function and returns `.None`. Else if the
1014
/// Optional is `.Some`, applies the function to its value and returns the result in a new `.Some`.
11-
public func <^> <A, B>(f : A -> B, a : A?) -> B? {
15+
public func <^> <A, B>(f : (A) -> B, a : A?) -> B? {
1216
return a.map(f)
1317
}
1418

@@ -17,7 +21,7 @@ public func <^> <A, B>(f : A -> B, a : A?) -> B? {
1721
/// result is `.None`.
1822
///
1923
/// Promotes function application to an Optional function applied to an Optional value.
20-
public func <*> <A, B>(f : (A -> B)?, a : A?) -> B? {
24+
public func <*> <A, B>(f : ((A) -> B)?, a : A?) -> B? {
2125
return f.flatMap { $0 <^> a }
2226
}
2327

@@ -26,6 +30,6 @@ public func <*> <A, B>(f : (A -> B)?, a : A?) -> B? {
2630
/// result is the application of the function to the value contained within.
2731
///
2832
/// Bind propagates any occurance of `.None` through a computation that may fail at several points.
29-
public func >>- <A, B>(a : A?, f : A -> B?) -> B? {
33+
public func >>- <A, B>(a : A?, f : (A) -> B?) -> B? {
3034
return a.flatMap(f)
3135
}

Swiftx/Swiftx.h Sources/Swiftx.h

File renamed without changes.

0 commit comments

Comments
 (0)