Skip to content

Instantly share code, notes, and snippets.

@circAssimilate
Last active February 10, 2022 23:06
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 circAssimilate/541dd6261746834720e0392ef909e28f to your computer and use it in GitHub Desktop.
Save circAssimilate/541dd6261746834720e0392ef909e28f to your computer and use it in GitHub Desktop.
Clamp method for Swift
func clamp<T: Comparable>(value: T, minValue: T, maxValue: T) -> T {
return max(
minValue,
min(
value,
maxValue
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment