Fallback icon indicating copy to clipboard operation
Fallback copied to clipboard

Add support chaining

Open devxoul opened this issue 9 years ago • 0 comments

This is for whom wants handle each errors.

From the comment from Reddit:

Keeps it short and sweet. My biggest concern is that it's limiting errors to control flow. If get("A") and get("B") fail and we get("C") instead, what happened to the errors from the previous 2 calls? It looks to me like it only throws the last error.

Examples

let value: String = fallback {
  return try get("a")
}.catch { error in // error from "a"
  return try get("b")
}.catch { error in // error from "b"
  return try get("c")
}.finally { error in // error from "c"
  return "none"
}
print(value) // "none"
let value: String = try fallback {
  return try get("a")
}.catch { error in // error from "a"
  return try get("b")
}.catch { error in // error from "b"
  return try get("c")
}.rethrow() // will throw error from "c"

To Do

  • [x] Implement
  • [x] Test
  • [ ] Documentation

devxoul avatar Oct 26 '16 21:10 devxoul