Last active
April 3, 2019 14:32
-
-
Save DanielCardonaRojas/cb9cc4d1b8ef584783cf4a2a61a7d4d6 to your computer and use it in GitHub Desktop.
Extensions on Equatable, Comparable, etc..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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