Extending Comparable to clamp values within a range
Daily Coding Tip 006
You may need to ensure a value is within a certain range, and conditional logic is in danger of human error. For instance, do we want to use the
< operator or the
<= operator? It helps to have an easy way to repeat this process in all cases, so that it works consistently as we expect and reduces the amount of code we need…
Keep reading with a 7-day free trial
Subscribe to Type Safely to keep reading this post and get 7 days of free access to the full post archives.