Skip to content

Instantly share code, notes, and snippets.

@yarneo
Created February 6, 2016 19:51
Show Gist options
  • Save yarneo/6d9490fe43dc136d958b to your computer and use it in GitHub Desktop.
Save yarneo/6d9490fe43dc136d958b to your computer and use it in GitHub Desktop.
protocol Summable { func +(lhs: Self, rhs: Self) -> Self }
extension Int: Summable {}
extension Double: Summable {}
extension String: Summable {}
func sum<T: Summable>(lhs:T, _ rhs:T) -> T {
return lhs + rhs
}
sum("Hello ", "World") // "Hello World"
sum(1, 4) // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment