From 51aad157e3999b11ca2dd731c5c205f0d678c3a0 Mon Sep 17 00:00:00 2001 From: Le Van Nghia Date: Mon, 1 Jun 2015 23:27:17 +0900 Subject: [PATCH] change operator precedence --- Future/Future.swift | 10 ++++++---- FutureTests/FutureFunctionalTests.swift | 26 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Future/Future.swift b/Future/Future.swift index a058c60..173aefc 100644 --- a/Future/Future.swift +++ b/Future/Future.swift @@ -222,17 +222,19 @@ infix operator <^> { // Left associativity associativity left - // Using the same `precedence` value with Swiftz's operator - precedence 140 + // precedence + precedence 150 } +/* infix operator >>- { // Left associativity associativity left - // Using the same `precedence` value with Swiftz's operator - precedence 140 + // Using the same `precedence` value in antitypical/Result + precedence 100 } +*/ // Operator for `map` public func <^> (future: Future, transform: T -> U) -> Future { diff --git a/FutureTests/FutureFunctionalTests.swift b/FutureTests/FutureFunctionalTests.swift index c528751..e7a616f 100644 --- a/FutureTests/FutureFunctionalTests.swift +++ b/FutureTests/FutureFunctionalTests.swift @@ -73,6 +73,32 @@ extension FutureFunctionalTests { } } + func testMapFlatMapOperators() { + let f = requestString("12345") <^> { count($0) } >>- requestStringFromNumber + + checkFutureShouldNotBeCompleted(f) + + f.onComplete { result in + switch result { + case .Success(let bv): XCTAssertEqual(bv.value, "5", "Future should return 5 as a String") + case .Failure(let be): XCTAssertFalse(true, "Future should not be failed") + } + } + } + + func testFlatMapMapOperators() { + let f = requestString("12345") >>- requestStringLenght <^> { "\($0)" } + + checkFutureShouldNotBeCompleted(f) + + f.onComplete { result in + switch result { + case .Success(let bv): XCTAssertEqual(bv.value, "5", "Future should return 5 as a String") + case .Failure(let be): XCTAssertFalse(true, "Future should not be failed") + } + } + } + func testFilter() { let noSuchElementError = NSError(domain: "noSuchElement", code: 1, userInfo: nil)