Skip to content

Commit

Permalink
Merge pull request #37 from CodaFi/big-merge
Browse files Browse the repository at this point in the history
Update to Swift 2.0
  • Loading branch information
CodaFi committed Sep 12, 2015
2 parents 497b3a1 + 7e4e404 commit ea6b999
Show file tree
Hide file tree
Showing 28 changed files with 813 additions and 924 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
*.xcscmblueprint
Carthage/

# CocoaPods
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
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
- xctool -project Swiftx.xcodeproj -scheme Swiftx-iOS -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO clean build test
before_install:
- gem install xcpretty-travis-formatter --no-rdoc --no-ri --no-document --quiet

install:
- git submodule update -i --recursive

script:
- 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`
Empty file added Cartfile
Empty file.
3 changes: 3 additions & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github "typelift/Operadics"
github "typelift/SwiftCheck"

2 changes: 2 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github "typelift/Operadics" "v0.1.3"
github "typelift/SwiftCheck" "v0.3.0"
1 change: 1 addition & 0 deletions Carthage/Checkouts/Operadics
Submodule Operadics added at a5897e
1 change: 1 addition & 0 deletions Carthage/Checkouts/SwiftCheck
Submodule SwiftCheck added at f80743
190 changes: 153 additions & 37 deletions Swiftx.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx-iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -62,6 +62,8 @@
ReferencedContainer = "container:Swiftx.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -71,6 +73,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
5 changes: 4 additions & 1 deletion Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -48,6 +48,8 @@
ReferencedContainer = "container:Swiftx.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -57,6 +59,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
5 changes: 4 additions & 1 deletion Swiftx.xcodeproj/xcshareddata/xcschemes/SwiftxTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -48,6 +48,8 @@
ReferencedContainer = "container:Swiftx.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -57,6 +59,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
41 changes: 14 additions & 27 deletions Swiftx/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,22 @@
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

/// Lifts a value into an Array.
public func pure<A>(a: A) -> [A] {
return [a]
/// 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] {
return xs.map(f)
}

/// Fmap | Maps a function over the contents of an array and returns a new array of the resulting
/// values.
public func <^> <A, B>(f: A -> B, a: [A]) -> [B] {
return a.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] {
return fs.flatMap({ xs.map($0) })
}

/// 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 <*> <A, B>(f: [(A -> B)], a: [A]) -> [B] {
var re = [B]()
for g in f {
for h in a {
re.append(g(h))
}
}
return re
}

/// 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, B>(a: [A], f: A -> [B]) -> [B] {
var re = [B]()
for x in a {
re.extend(f(x))
}
return re
/// 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] {
return xs.flatMap(f)
}
37 changes: 0 additions & 37 deletions Swiftx/Box.swift

This file was deleted.

147 changes: 147 additions & 0 deletions Swiftx/Combinators.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// Functions.swift
// Swiftx
//
// Created by Maxwell Swadling on 3/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
//

/// The identity function.
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 {
return { _ in x }
}

/// Flip a function's arguments
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 function that takes the arguments in flipped order.
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 {
return { b in { a in f(a)(b) } }
}

/// Compose | Applies one function to the result of another function to produce a third function.
///
/// 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 {
return { (a : A) -> C in
return f(g(a))
}
}

/// Apply | Applies an argument to a function.
///
///
/// Because of this operator's extremely low precedence it can be used to elide parenthesis in
/// complex expressions. For example:
///
/// f § g § h § x = f(g(h(x)))
///
/// Key Chord: ⌥ + 6
public func § <A, B>(f : A -> B, a : A) -> B {
return f(a)
}

/// Pipe Backward | Applies the function to its left to an argument on its right.
///
/// Because of this operator's extremely low precedence it can be used to elide parenthesis in
/// complex expressions. For example:
///
/// f <| g <| h <| x = f (g (h x))
///
/// Acts as a synonym for §.
public func <| <A, B>(f : A -> B, a : A) -> B {
return f(a)
}

/// Pipe forward | Applies an argument on the left to a function on the right.
///
/// Complex expressions may look more natural when expressed with this operator rather than normal
/// argument application. For example:
///
/// { $0 * $0 }({ $0.advancedBy($0) }({ $0.advancedBy($0) }(1)))
///
/// can also be written as:
///
/// 1 |> { $0.advancedBy($0) }
/// |> { $0.advancedBy($0) }
/// |> { $0 * $0 }
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 {
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 {
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.
///
/// 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 |*| <A, B, C>(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 |*| <A, B, C>(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<A, B, C>(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<A, B, C>(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<A>(p : A -> Bool) -> (A -> A) -> A -> A {
return { f in { x in p(x) ? x : until(p)(f)(f(x)) } }
}
Loading

0 comments on commit ea6b999

Please sign in to comment.