Swift 1.2: Transitive @noescape-like attribute for returned closures
| Originator: | rix.rob | ||
| Number: | rdar://19952226 | Date Originated: | 25-Feb-2015 10:25 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (6D532l) |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
I have a function composition operator defined like so in Prelude.framework[1]:
public func >>> <T, U, V> (f: T -> U, g: U -> V) -> T -> V {
return { g(f($0)) }
}
Now I want to use it to implement Either.map[2]:
extension Either {
public func map<V>(f: U -> V) -> Either<T, V> {
return either(ifLeft: Either<T, V>.left, ifRight: f >>> Either<T, V>.right)
}
}
Great! Being a good citizen I now want to mark map’s parameter as @noescape. However, if I do that, I can’t use >>> to compose f with the Either.right static function, because I don’t have a way to indicate to Swift that the operands to >>> will not escape if the returned closure does not escape. As a result, I have to either forego @noescape, or forego my composition operator.
I’d love to be able to tell Swift that >>>’s operands are captured completely by its returned closure and do not otherwise escape it.
Steps to Reproduce:
N/A
Expected Results:
N/A
Actual Results:
N/A
Regression:
N/A
Notes:
1: https://github.com/robrix/Prelude
2: https://github.com/robrix/Either
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!