Last active
March 3, 2020 13:23
-
-
Save dnedrow/e7346890e6b4bb568fe95228c60bf82c to your computer and use it in GitHub Desktop.
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
| // Comparable+Extensions.swift | |
| // Attribution 4.0 International (CC 4.0), see bottom for license details. | |
| import Foundation | |
| extension Comparable { | |
| func clamp<T: Comparable>(lower: T, _ upper: T) -> T { | |
| assert(lower <= upper) | |
| return min(max(self as! T, lower), upper) | |
| } | |
| } | |
| // This work is licensed under Attribution 4.0 International (CC 4.0) | |
| // You are free to: | |
| // Share — copy and redistribute the material in any medium or format | |
| // Adapt — remix, transform, and build upon the material | |
| // for any purpose, even commercially. | |
| // | |
| // This license is acceptable for Free Cultural Works. | |
| // The licensor cannot revoke these freedoms as long as you follow the license terms. | |
| // See https://creativecommons.org/licenses/by/4.0/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment