Skip to content

Commit

Permalink
updated versions + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dileping committed Mar 18, 2017
1 parent 6d41b8d commit 505ef56
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "reactive-swift/Event" ~> 0.2
github "reactive-swift/Event" ~> 0.3
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ import PackageDescription
let package = Package(
name: "Future",
dependencies: [
.Package(url: "https://github.com/reactive-swift/Event.git", "0.3.0-alpha.1")
.Package(url: "https://github.com/reactive-swift/Event.git", "0.3.0-alpha")
]
)
15 changes: 3 additions & 12 deletions Sources/Future/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ import Foundation
import Boilerplate

public enum FutureError : Error {
case AlreadyCompleted
case MappedNil
case FilteredOut
}

internal func anyError(_ e:Error) -> AnyError {
switch e {
case let error as AnyError:
return error
default:
return AnyError(e)
}
case alreadyCompleted
case mappedNil
case filteredOut
}
14 changes: 7 additions & 7 deletions Sources/Future/Future+Functional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public extension FutureProtocol {

self.onComplete { (result:Result<Value, AnyError>) in
let result = result.flatMap { value -> Result<B, AnyError> in
materializeAny {
materialize {
try f(value)
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public extension FutureProtocol {
self.onComplete { (result:Result<Value, AnyError>) in
let result:Result<B, AnyError> = result.flatMap { value in
guard let b = f(value) else {
return Result(error: AnyError(FutureError.MappedNil))
return Result(error: AnyError(FutureError.mappedNil))
}
return Result(value: b)
}
Expand All @@ -128,7 +128,7 @@ public extension FutureProtocol {
if f(value) {
try! future.success(value: value)
} else {
try! future.fail(error: FutureError.FilteredOut)
try! future.fail(error: FutureError.filteredOut)
}
}, ifFailure: { error in
try! future.fail(error: error)
Expand All @@ -148,8 +148,8 @@ public extension FutureProtocol {
let future = MutableFuture<Value>(context: self.context)

self.onComplete { (result:Result<Value, E>) in
let result = result.flatMapError { error in
return materializeAny {
let result = result.flatMapError { error -> Result<Value, AnyError> in
return materialize {
try f(error)
}
}
Expand All @@ -167,8 +167,8 @@ public extension FutureProtocol {
let future = MutableFuture<Value>(context: self.context)

self.onComplete { (result:Result<Value, AnyError>) in
let result = result.flatMapError { error in
return materializeAny {
let result = result.flatMapError { error -> Result<Value, AnyError> in
return materialize {
try f(error.error)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Future/MutableFuture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class MutableFuture<V> : Future<V>, MutableFutureType {
public extension MutableFutureType {
func complete<E : Error>(result:Result<Value, E>) throws {
if !tryComplete(result: result) {
throw FutureError.AlreadyCompleted
throw FutureError.alreadyCompleted
}
}

Expand All @@ -54,17 +54,17 @@ public extension MutableFutureType {

func success(value:Value) throws {
if !trySuccess(value: value) {
throw FutureError.AlreadyCompleted
throw FutureError.alreadyCompleted
}
}

func tryFail(error:Error) -> Bool {
return tryComplete(result: Result(error: anyError(error)))
return tryComplete(result: Result(error: AnyError(error)))
}

func fail(error:Error) throws {
if !tryFail(error: error) {
throw FutureError.AlreadyCompleted
throw FutureError.alreadyCompleted
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Future/Result+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal extension Result {

func asAnyError() -> Result<T, AnyError> {
return self.mapError { error in
return anyError(error)
return AnyError(error)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/FutureTests/FutureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class FutureTests: XCTestCase {

let e = self.expectation()
f.onFailure { (err:FutureError) in
XCTAssertEqual(err, FutureError.FilteredOut)
XCTAssertEqual(err, FutureError.filteredOut)
e.fulfill()
}

Expand Down Expand Up @@ -753,7 +753,7 @@ class FutureTests: XCTestCase {
let e = self.expectation()

Future<Int>(value: 3).filter { $0 > 5}.onComplete { (result:Result<Int, FutureError>) in
XCTAssertEqual(result.error!, FutureError.FilteredOut, "filter should yield no result")
XCTAssertEqual(result.error!, FutureError.filteredOut, "filter should yield no result")
e.fulfill()
}

Expand Down

0 comments on commit 505ef56

Please sign in to comment.