Last active
August 29, 2015 14:26
-
-
Save alexanderedge/845c0f3bd5aaf2e035c2 to your computer and use it in GitHub Desktop.
Swift protocol extensions
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
protocol Raisable { | |
func raise(exponent : Self) -> Self | |
} | |
extension Raisable where Self : SignedNumberType { | |
func raise(exponent : Self) { | |
return pow(self, exponent) | |
} | |
} | |
protocol Squarable : Raisable { | |
func squared() -> Self | |
} | |
extension Squarable { | |
func squared() -> Self { | |
return self.raise(2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/31702831/swift-2-protocol-extension-using-pow/31703542#31703542