Skip to content

Instantly share code, notes, and snippets.

@brandonvanha
Last active February 27, 2018 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonvanha/f50fa1ce40132f648319e7f8390060bf to your computer and use it in GitHub Desktop.
Save brandonvanha/f50fa1ce40132f648319e7f8390060bf to your computer and use it in GitHub Desktop.
protocol Numeric {
func *(lhs: Self, rhs: Self) -> Self
}
extension Double: Numeric {}
extension Float: Numeric {}
extension Int: Numeric {}
func genericMultiplier<T: Numeric>(lhs: T, rhs: T) -> T {
return lhs * rhs
}
genericMultiplier(lhs: 5, rhs: 6)
genericMultiplier(lhs: 18.2 rhs: 19.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment