Type Safely

Type Safely

Share this post

Type Safely
Type Safely
Extending Comparable to clamp values within a range

Extending Comparable to clamp values within a range

Daily Coding Tip 006

Type Safely's avatar
Type Safely
Dec 24, 2020
∙ Paid

Share this post

Type Safely
Type Safely
Extending Comparable to clamp values within a range
Share
Image by Karl Egger from Pixabay

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.

Already a paid subscriber? Sign in
© 2025 Type Safely
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share