Promisekit: Coding Style in documentation for chained operations

Created on 6 Sep 2018  路  2Comments  路  Source: mxcl/PromiseKit

Hello,
In documentation and examples this coding style is used a lot:

firstly {
    when(fulfilled: fetchImage, fetchLocation)
}.done { image, location in
    self.imageView.image = image
    self.label.text = "\(location)"
}.ensure {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch { error in
    self.show(UIAlertController(for: error), sender: self)
}

But it is not so usual for swift, any advantages for this?

In other libraries:
RxSwift

let searchResults = searchBar.rx.text.orEmpty
    .throttle(0.3, scheduler: MainScheduler.instance)
    .distinctUntilChanged()
    .flatMapLatest { query -> Observable<[Repository]> in
        if query.isEmpty {
            return .just([])
        }
        return searchGitHub(query)
            .catchErrorJustReturn([])
    }
    .observeOn(MainScheduler.instance)

ReactiveSwift

signal
    .mapError { (error: NSError) -> CustomError in
        switch error.domain {
        case "com.example.foo":
            return .foo
        case "com.example.bar":
            return .bar
        default:
            return .other
        }
    }
    .observeFailed { error in
        print(error.rawValue)
}

RW Style examples

let value = numbers
  .map {$0 * 2}
  .filter {$0 > 50}
  .map {$0 + 10}

Most helpful comment

Our choice emphasizes that you read between the lines to see the sequence of operations, which I think is more readable for our use.

Promises are sequences of tasks, so this is different to the other examples you provide, which functionally modify things. With promises, mostly the function that you are calling is irrelevant, all that matters is the content of the closures.

All 2 comments

Our choice emphasizes that you read between the lines to see the sequence of operations, which I think is more readable for our use.

Promises are sequences of tasks, so this is different to the other examples you provide, which functionally modify things. With promises, mostly the function that you are calling is irrelevant, all that matters is the content of the closures.

Closing due to stagnation, if you have further questions reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guidedways picture guidedways  路  4Comments

drekka picture drekka  路  5Comments

jshier picture jshier  路  4Comments

katopz picture katopz  路  4Comments

victoraraujo01 picture victoraraujo01  路  3Comments