Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Last active April 3, 2019 14:32
Show Gist options
  • Save DanielCardonaRojas/cb9cc4d1b8ef584783cf4a2a61a7d4d6 to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/cb9cc4d1b8ef584783cf4a2a61a7d4d6 to your computer and use it in GitHub Desktop.
Extensions on Equatable, Comparable, etc..
extension Comparable {
func clamped(min: Self, max: Self) -> Self {
if self < min {
return min
}
if self > max {
return max
}
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment