Skip to content

Instantly share code, notes, and snippets.

@efremidze
Created October 23, 2017 19:17
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 efremidze/08714511d6e504e1ff5b079209a966a1 to your computer and use it in GitHub Desktop.
Save efremidze/08714511d6e504e1ff5b079209a966a1 to your computer and use it in GitHub Desktop.
extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> Self {
return min(max(self, limits.lowerBound), limits.upperBound)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment