Skip to content

Commit

Permalink
Merge pull request #58 from typelift/swift-develop
Browse files Browse the repository at this point in the history
Update to Swift 3.0
  • Loading branch information
CodaFi authored Sep 18, 2016
2 parents 7aeae54 + 26e9c91 commit 0a2dda8
Show file tree
Hide file tree
Showing 31 changed files with 252 additions and 2,908 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Xcode
.DS_Store
.build/*
Packages/*
build/*
*.pbxuser
!default.pbxuser
Expand Down
61 changes: 48 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
language: objective-c
osx_image: xcode7.3
env:
- TEST_CONFIG="RELEASE"
- TEST_CONFIG="PODS"

before_install: true
install: true
script:
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then script/cibuild Swiftx ; fi
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then xcodebuild test -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' ; fi
- if [[ "$TEST_CONFIG" == "RELEASE" ]]; then xcodebuild build -scheme Swiftx-watchOS -destination 'platform=watchOS Simulator,name=Apple Watch - 42mm' ; fi
- if [[ "$TEST_CONFIG" == "PODS" ]]; then pod lib lint; fi

global:
- LC_CTYPE=en_US.UTF-8
matrix:
include:
- os: osx
language: objective-c
osx_image: xcode8
before_install:
- git submodule update --init --recursive
script:
# Restore pod build before shipping for 3.0
# - pod lib lint
- carthage build --no-skip-current
- os: osx
language: objective-c
osx_image: xcode8
before_install:
- git submodule update --init --recursive
script:
- set -o pipefail
- xcodebuild test -scheme Swiftx | xcpretty -c
# -- Start iOS --
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
- iOS_DEVICE_NAME="iPad Pro (12.9 inch)"
- iOS_RUNTIME_VERSION="10.0"
# Get simulator identifier for desired device/runtime pair
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
- echo $SIMULATOR_ID
- echo $iOS_DEVICE_NAME
- echo $iOS_RUNTIME_VERSION
# !!!: Start simulator w/ desired device—helps avoid issues w/ Xcode timing out when waiting for simulator to become ready
- open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $SIMULATOR_ID
- xcodebuild test -scheme Swiftx-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
# -- End iOS --
- xcodebuild test -scheme Swiftx-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
- os: linux
language: generic
sudo: required
dist: trusty
before_install:
- git submodule update --init --recursive
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
- wget https://swift.org/builds/swift-3.0-release/ubuntu1404/swift-3.0-RELEASE/swift-3.0-RELEASE-ubuntu14.04.tar.gz
- tar xzf swift-3.0-RELEASE-ubuntu14.04.tar.gz
- export PATH=${PWD}/swift-3.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
script:
- swift build
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/1d781e1bcbabade5de35
on_success: always
on_failure: always
on_start: always

2 changes: 1 addition & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "typelift/Operadics"
github "typelift/Operadics"
github "typelift/SwiftCheck"

4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "typelift/Operadics" "0.2.0"
github "typelift/SwiftCheck" "v0.6.0"
github "typelift/Operadics" "0.2.2"
github "typelift/SwiftCheck" "v0.7.0"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Operadics
Submodule Operadics updated 3 files
+1 −0 .gitignore
+112 −132 Operators.swift
+2 −0 Package.swift
2 changes: 1 addition & 1 deletion Carthage/Checkouts/SwiftCheck
Submodule SwiftCheck updated 53 files
+2 −0 .gitignore
+0 −3 .gitmodules
+22 −13 .travis.yml
+0 −1 Cartfile.private
+0 −1 Cartfile.resolved
+0 −1 Carthage/Checkouts/Operadics
+0 −2 Package.swift
+65 −12 README.md
+77 −79 Sources/Arbitrary.swift
+173 −46 Sources/Check.swift
+59 −56 Sources/CoArbitrary.swift
+89 −0 Sources/Compose.swift
+296 −152 Sources/Gen.swift
+26 −26 Sources/Lattice.swift
+121 −97 Sources/Modifiers.swift
+0 −246 Sources/Operators.swift
+392 −264 Sources/Property.swift
+84 −51 Sources/Random.swift
+55 −67 Sources/Rose.swift
+48 −47 Sources/State.swift
+0 −1 Sources/SwiftCheck.h
+624 −408 Sources/Test.swift
+0 −129 Sources/TestOperators.swift
+20 −33 Sources/Testable.swift
+109 −17 Sources/Witness.swift
+111 −101 Sources/WitnessedArbitrary.swift
+1 −1 SwiftCheck.podspec
+51 −26 SwiftCheck.xcodeproj/project.pbxproj
+1 −1 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck-iOS.xcscheme
+1 −1 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck-tvOS.xcscheme
+5 −5 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck.xcscheme
+20 −14 Tests/ComplexSpec.swift
+6 −5 Tests/DiscardSpec.swift
+10 −10 Tests/FailureSpec.swift
+156 −25 Tests/GenSpec.swift
+47 −47 Tests/LambdaSpec.swift
+5 −7 Tests/ModifierSpec.swift
+38 −38 Tests/PathSpec.swift
+37 −19 Tests/PropertySpec.swift
+36 −0 Tests/RawRepresentableSpec.swift
+2 −2 Tests/ReplaySpec.swift
+113 −31 Tests/RoseSpec.swift
+1 −10 Tests/ShrinkSpec.swift
+142 −9 Tests/SimpleSpec.swift
+8 −21 Tests/TestSpec.swift
+22 −87 Tutorial.playground/Contents.swift
+1 −1 Tutorial.playground/contents.xcplayground
+0 −18 script/LICENSE.md
+0 −82 script/README.md
+0 −47 script/bootstrap
+0 −173 script/cibuild
+0 −10 script/schemes.awk
+0 −25 script/xctool.awk
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import PackageDescription

let package = Package(
name: "Swiftx",
targets: [
Target(name: "Swiftx"),
],
dependencies: [
.Package(url: "https://github.com/typelift/Operadics.git", versions: Version(0,2,2)...Version(0,2,2))
]
)

let libSwiftx = Product(name: "Swiftx", type: .Library(.Dynamic), modules: "Swiftx")
products.append(libSwiftx)
10 changes: 7 additions & 3 deletions Swiftx/Array.swift → Sources/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

#if !XCODE_BUILD
import Operadics
#endif

/// 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 <^> <A, B>(f : A -> B, xs : [A]) -> [B] {
public func <^> <A, B>(f : (A) -> B, xs : [A]) -> [B] {
return xs.map(f)
}

/// 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 arrays of functions applied to arrays of elements.
public func <*> <A, B>(fs : [(A -> B)], xs : [A]) -> [B] {
public func <*> <A, B>(fs : [((A) -> B)], xs : [A]) -> [B] {
return fs.flatMap({ xs.map($0) })
}

/// Bind | Returns the result of mapping the given function over the given array of elements and
/// concatenating the result.
public func >>- <A, B>(xs : [A], f : A -> [B]) -> [B] {
public func >>- <A, B>(xs : [A], f : (A) -> [B]) -> [B] {
return xs.flatMap(f)
}
35 changes: 20 additions & 15 deletions Swiftx/Combinators.swift → Sources/Combinators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

#if !XCODE_BUILD
import Operadics
#endif

/// The identity function.
public func identity<A>(a : A) -> A {
public func identity<A>(_ a : A) -> A {
return a
}

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

/// Flip a function's arguments
public func flip<A, B, C>(f : ((A, B) -> C), _ b : B, _ a : A) -> C {
public func flip<A, B, C>(_ 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<A, B, C>(f : A -> B -> C) -> B -> A -> C {
public func flip<A, B, C>(_ f : @escaping (A) -> (B) -> C) -> (B) -> (A) -> C {
return { b in { a in f(a)(b) } }
}

Expand All @@ -32,7 +36,7 @@ public func flip<A, B, C>(f : A -> B -> C) -> B -> A -> C {
/// f : B -> C
/// g : A -> B
/// (f • g)(x) === f(g(x)) : A -> B -> C
public func <A, B, C>(f : B -> C, g : A -> B) -> A -> C {
public func <A, B, C>(f : @escaping (B) -> C, g : @escaping (A) -> B) -> (A) -> C {
return { (a : A) -> C in
return f(g(a))
}
Expand All @@ -47,7 +51,7 @@ public func • <A, B, C>(f : B -> C, g : A -> B) -> A -> C {
/// f § g § h § x = f(g(h(x)))
///
/// Key Chord: ⌥ + 6
public func § <A, B>(f : A -> B, a : A) -> B {
public func § <A, B>(f : (A) -> B, a : A) -> B {
return f(a)
}

Expand All @@ -59,7 +63,7 @@ public func § <A, B>(f : A -> B, a : A) -> B {
/// f <| g <| h <| x = f (g (h x))
///
/// Acts as a synonym for §.
public func <| <A, B>(f : A -> B, a : A) -> B {
public func <| <A, B>(f : (A) -> B, a : A) -> B {
return f(a)
}

Expand All @@ -75,25 +79,26 @@ public func <| <A, B>(f : A -> B, a : A) -> B {
/// 1 |> { $0.advancedBy($0) }
/// |> { $0.advancedBy($0) }
/// |> { $0 * $0 }
public func |> <A, B>(a : A, f : A -> B) -> B {
public func |> <A, B>(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<A, B>(f : (A -> B) -> A -> B) -> A -> B {
public func fix<A, B>(_ f : @escaping ((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<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -> A throws -> B {
public func fixt<A, B>(_ f : @escaping ((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
/// left to the result of both prior applications.
///
Expand All @@ -103,7 +108,7 @@ public func fixt<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -
///
/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")]
/// let sortedByFirstIndex = arr.sort((<) |*| fst)
public func |*| <A, B, C>(o : B -> B -> C, f : A -> B) -> A -> A -> C {
public func |*| <A, B, C>(o : @escaping (B) -> (B) -> C, f : @escaping (A) -> B) -> (A) -> (A) -> C {
return on(o)(f)
}

Expand All @@ -116,27 +121,27 @@ public func |*| <A, B, C>(o : B -> B -> C, f : A -> B) -> A -> A -> C {
///
/// let arr : [(Int, String)] = [(2, "Second"), (1, "First"), (5, "Fifth"), (3, "Third"), (4, "Fourth")]
/// let sortedByFirstIndex = arr.sort((<) |*| fst)
public func |*| <A, B, C>(o : (B, B) -> C, f : A -> B) -> A -> A -> C {
public func |*| <A, B, C>(o : @escaping (B, B) -> C, f : @escaping (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<A, B, C>(o : B -> B -> C) -> (A -> B) -> A -> A -> C {
public func on<A, B, C>(_ o : @escaping (B) -> (B) -> C) -> (@escaping (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<A, B, C>(o : (B, B) -> C) -> (A -> B) -> A -> A -> C {
public func on<A, B, C>(_ o : @escaping (B, B) -> C) -> (@escaping (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<A>(p : A -> Bool) -> (A -> A) -> A -> A {
public func until<A>(_ p : @escaping (A) -> Bool) -> (@escaping (A) -> A) -> (A) -> A {
return { f in { x in p(x) ? x : until(p)(f)(f(x)) } }
}
16 changes: 10 additions & 6 deletions Swiftx/Either.swift → Sources/Either.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

#if !XCODE_BUILD
import Operadics
#endif

/// The `Either` type represents values with two possibilities: `.Left(L)` or `.Right(R)`.
///
/// The `Either` type is right-biased by convention. That is, the `.Left` constructor is used to
Expand All @@ -20,22 +24,22 @@ public enum Either<L, R> {
/// Much like the ?? operator for `Optional` types, takes a value and a function, and if the
/// receiver is `.Left`, returns the value, otherwise maps the function over the value in
/// `.Right` and returns that value.
public func fold<B>(value : B, f : R -> B) -> B {
public func fold<B>(_ value : B, f : (R) -> B) -> B {
return either(onLeft: const(value), onRight: f);
}

/// 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<S>(f : R -> Either<L, S>) -> Either<L, S> {
public func flatMap<S>(_ f : (R) -> Either<L, S>) -> Either<L, S> {
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`.
public func either<A>(onLeft onLeft : L -> A, onRight : R -> A) -> A {
public func either<A>(onLeft : (L) -> A, onRight : (R) -> A) -> A {
switch self {
case let .Left(e):
return onLeft(e)
Expand Down Expand Up @@ -74,7 +78,7 @@ public enum Either<L, R> {
/// 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 <^> <L, RA, RB>(f : RA -> RB, e : Either<L, RA>) -> Either<L, RB> {
public func <^> <L, RA, RB>(f : (RA) -> RB, e : Either<L, RA>) -> Either<L, RB> {
switch e {
case let .Left(l):
return .Left(l)
Expand All @@ -90,7 +94,7 @@ public func <^> <L, RA, RB>(f : RA -> RB, e : Either<L, RA>) -> Either<L, RB> {
/// 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 <*> <L, RA, RB>(f : Either<L, RA -> RB>, e : Either<L, RA>) -> Either<L, RB> {
public func <*> <L, RA, RB>(f : Either<L, (RA) -> RB>, e : Either<L, RA>) -> Either<L, RB> {
switch (f, e) {
case let (.Left(l), _):
return .Left(l)
Expand All @@ -104,7 +108,7 @@ public func <*> <L, RA, RB>(f : Either<L, RA -> RB>, e : Either<L, RA>) -> Eithe
/// If the `Either` is `.Left`, the given function is ignored and the result of this function is
/// `.Left`. Else the result of this function is the application of the function to the value
/// contained in the `Either`.
public func >>- <L, RA, RB>(a : Either<L, RA>, f : RA -> Either<L, RB>) -> Either<L, RB> {
public func >>- <L, RA, RB>(a : Either<L, RA>, f : (RA) -> Either<L, RB>) -> Either<L, RB> {
switch a {
case let .Left(l):
return .Left(l)
Expand Down
2 changes: 1 addition & 1 deletion Swiftx/Error.swift → Sources/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

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

Expand Down
File renamed without changes.
10 changes: 7 additions & 3 deletions Swiftx/Optional.swift → Sources/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

#if !XCODE_BUILD
import Operadics
#endif

/// 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 <^> <A, B>(f : A -> B, a : A?) -> B? {
public func <^> <A, B>(f : (A) -> B, a : A?) -> B? {
return a.map(f)
}

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

Expand All @@ -26,6 +30,6 @@ public func <*> <A, B>(f : (A -> B)?, a : A?) -> B? {
/// 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, B>(a : A?, f : A -> B?) -> B? {
public func >>- <A, B>(a : A?, f : (A) -> B?) -> B? {
return a.flatMap(f)
}
File renamed without changes.
Loading

0 comments on commit 0a2dda8

Please sign in to comment.