Skip to content

Commit

Permalink
Merge pull request #7 from CodaFi/swift-1-dot-2
Browse files Browse the repository at this point in the history
[WIP] Swift 1.2
  • Loading branch information
CodaFi committed May 8, 2015
2 parents e0997a4 + 3de50da commit 02d8b76
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 97 deletions.
19 changes: 19 additions & 0 deletions Swiftx-iOS.xcodeproj/xcshareddata/xcschemes/Swiftx.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84A88CB91A70BD82003D53CF"
BuildableName = "Swiftx-iOSTests.xctest"
BlueprintName = "Swiftx-iOSTests"
ReferencedContainer = "container:Swiftx-iOS.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84A88D0F1A70BE0D003D53CF"
BuildableName = "Swiftx.framework"
BlueprintName = "Swiftx"
ReferencedContainer = "container:Swiftx-iOS.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand Down
19 changes: 19 additions & 0 deletions Swiftx.xcodeproj/xcshareddata/xcschemes/Swiftx.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84A88C931A70BD71003D53CF"
BuildableName = "SwiftxTests.xctest"
BlueprintName = "SwiftxTests"
ReferencedContainer = "container:Swiftx.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84A88C881A70BD71003D53CF"
BuildableName = "Swiftx.framework"
BlueprintName = "Swiftx"
ReferencedContainer = "container:Swiftx.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand Down
2 changes: 1 addition & 1 deletion Swiftx/Array.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Array.swift
// swiftz_core
// Swiftx
//
// Created by Maxwell Swadling on 3/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
Expand Down
19 changes: 10 additions & 9 deletions Swiftx/Box.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
//
// Box.swift
// swiftz_core
// Swiftx
//
// Created by Andrew Cobb on 6/9/14.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
// 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<T> {
private let val : @autoclosure () -> T
public var value: T { return val() }

public init(_ value : T) {
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<U>(f : T -> U) -> Box<U> {
return Box<U>(f(value))
return Box<U>(f(self.value))
}
}

/// Fmap | Applies a function to the value of the receiver to yield a new box.
public func <^> <T, U>(f: T -> U, x: Box<T>) -> Box<U> {
public func <^> <T, U>(f : T -> U, x : Box<T>) -> Box<U> {
return x.map(f)
}

Expand Down
6 changes: 3 additions & 3 deletions Swiftx/Either.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Either.swift
// swiftz
// Swiftx
//
// Created by Maxwell Swadling on 3/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
Expand All @@ -21,15 +21,15 @@ public enum Either<L, 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<R> {
return either({ e in Result.Error(ev(e)) }, { v in .Value(Box(v)) });
return either(onLeft: { e in Result.Error(ev(e)) }, onRight: { v in .Value(Box(v)) });
}


/// 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.
public func fold<B>(value : B, f : R -> B) -> B {
return either({ _ in value }, { r in f(r) });
return either(onLeft: { _ in value }, onRight: { r in f(r) });
}

/// Named function for `>>-`. If the Either is Left, simply returns
Expand Down
8 changes: 5 additions & 3 deletions Swiftx/Error.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//
// Error.swift
// swiftz_core
// Swiftx
//
// Created by Robert Widmann on 12/23/14.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
// Copyright (c) 2014 TypeLift. All rights reserved.
//

/// Immediately terminates the program with an error message.
///
/// TODO: Find a way to silence this warning [-wunreachable-code]
public func error<A>(x : String) -> A {
return fatalError(x) as A
return fatalError(x) as! A
}

/// A special case of error.
Expand Down
4 changes: 2 additions & 2 deletions Swiftx/Functions.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// Functions.swift
// swiftz_core
// 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 {
public func identity<A>(a : A) -> A {
return a
}

Expand Down
2 changes: 1 addition & 1 deletion Swiftx/Nothing.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Nothing.swift
// swiftz_core
// Swiftx
//
// Created by Maxwell Swadling on 18/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
Expand Down
6 changes: 3 additions & 3 deletions Swiftx/Operators.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Operators.swift
// swiftz_core
// Swiftx
//
// Created by Maxwell Swadling on 28/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
// Created by Robert Widmann on 28/06/2014.
// Copyright (c) 2014 TypeLift. All rights reserved.
//

/// MARK: Combinators
Expand Down
2 changes: 1 addition & 1 deletion Swiftx/Optional.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Optional.swift
// swiftz_core
// Swiftx
//
// Created by Maxwell Swadling on 3/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Swiftx/Result.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Result.swift
// swiftz
// Swiftx
//
// Created by Maxwell Swadling on 9/06/2014.
// Copyright (c) 2014 Maxwell Swadling. All rights reserved.
Expand Down
Loading

0 comments on commit 02d8b76

Please sign in to comment.