From af105e75562ba441c552c71982cc08cc9a13befb Mon Sep 17 00:00:00 2001 From: nghialv Date: Fri, 5 Jun 2015 00:12:50 +0900 Subject: [PATCH] update Readme --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index cde95b4..cddeb95 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,29 @@ Usage ----- - `map` `<^>` + +```swift +let f = requestUser("nghialv") <^> { $0.id } + +f.onSuccess { userId in + println(userId) +} + +``` + - `flatMap` `>>-` + +```swift +let f = searchRepositories("Hakuba") <^> { $0.first!.ownerName } >>- requestUser + +f.onComplete { result in + switch result { + case .Success(let user): println(user) + case .Failure(let error): println(error) + } +} +``` + - `filter` ``` swift @@ -94,6 +116,28 @@ f.onComplete { result in ``` - `andThen` + +```swift +// side-effect +var reposCount = 0 + +let f1 = searchRepositories("Hakuba") +let f2 = f1.andThen { result in + switch result { + case .Success(let repos): reposCount = repos.value.count + case .Failure(let error): break + } +} +let f3 = f2 <^> { $0.first!.ownerName } >>- requestUser + +f3.onComplete { result in + switch result { + case .Success(let user): println(user) + case .Failure(let error): println(error) + } +} +``` + - `recover` - `zip` - `flatten`