Created
June 17, 2016 15:33
-
-
Save lammertw/925a21bc1b670567172881e8addbf45b to your computer and use it in GitHub Desktop.
Filter objects into Optionals
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
extension Filter { | |
/// Allows filtering of non sequence types. | |
/// | |
/// let label = UILabel().then { | |
/// $0.textAlignment = .Center | |
/// $0.textColor = UIColor.blackColor() | |
/// $0.text = "Hello, World!" | |
/// } | |
public func filter(@noescape condition: Self -> Bool) -> Self? { | |
return condition(self) ? self : nil | |
} | |
} | |
extension NSObject: Filter {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment