Created
April 8, 2019 01:53
-
-
Save anettodev/ee0ecb91853bc0c36195f0f41d84d143 to your computer and use it in GitHub Desktop.
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
// Custom Protocol | |
protocol CustomAddable { | |
static func +(lhs: Self, rhs: Self) -> Self | |
} | |
// Sum 2 Numeric elements | |
func sum<T: CustomAddable>(x: T, y: T) -> T { | |
return x + y | |
} | |
// extending to work with the Custom Protocol | |
extension Int: CustomAddable {} | |
extension Double: CustomAddable {} | |
extension Float: CustomAddable {} | |
sum(3, 4.5) // result 7.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment