Hey not sure if that would add value to others, bu...
# stdlib
x
Hey not sure if that would add value to others, but it would be nice to have a
clamp
method on Numbers in the StdLib :
Copy code
fun clamp(d: Double, min : Double, max : Double) : Double {
    return if (d < min) {
        min
    } else if (d > max) {
        max
    } else {
        d
    }
}
or
Copy code
fun Double.clamp(min : Double, max : Double) : Double {
    return if (this< min) {
        min
    } else if (this > max) {
        max
    } else {
        this
    }
}
n
i’m always amazed that there are such functions and even more when people know about them