mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
add clamp
This commit is contained in:
parent
527f7bbafe
commit
90c0817b6d
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.4.11
|
## 0.4.11
|
||||||
|
|
||||||
|
* `Common`
|
||||||
|
* Add `clamp` function
|
||||||
|
|
||||||
## 0.4.10
|
## 0.4.10
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun <T : Comparable<T>> T.clamp(min: T, max: T): T {
|
||||||
|
return when {
|
||||||
|
this < min -> min
|
||||||
|
this > max -> max
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user