diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec8418a370..d00f69cbe2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.4.11 +* `Common` + * Add `clamp` function + ## 0.4.10 * `Versions`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt new file mode 100644 index 00000000000..98eab69372c --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Clamp.kt @@ -0,0 +1,10 @@ +package dev.inmo.micro_utils.common + +@Suppress("NOTHING_TO_INLINE") +inline fun > T.clamp(min: T, max: T): T { + return when { + this < min -> min + this > max -> max + else -> this + } +}