Skip to content

Instantly share code, notes, and snippets.

@alexanderedge
Last active August 29, 2015 14:26
Show Gist options
  • Save alexanderedge/845c0f3bd5aaf2e035c2 to your computer and use it in GitHub Desktop.
Save alexanderedge/845c0f3bd5aaf2e035c2 to your computer and use it in GitHub Desktop.
Swift protocol extensions
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