Created
March 27, 2015 13:35
-
-
Save pyrtsa/c134bdbc3e6153a0a93c to your computer and use it in GitHub Desktop.
An object initialisation operator in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix operator => { associativity left precedence 100 } | |
infix operator =>? { associativity left precedence 100 } | |
/// Perform side effects on `x` and then return it. Example: | |
/// | |
/// self.label = UILabel(frame: frame) => { l in | |
/// l.text = "Hello?" | |
/// } | |
func =><T>(x: T, f: T -> ()) -> T { | |
f(x) | |
return x | |
} | |
func =>?<T>(x: T?, f: T -> ()) -> T? { | |
if let y = x { f(y) } | |
return x | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment