Skip to content

Commit

Permalink
refactor: update Number.toStrictlyNegativeInt() extension function
Browse files Browse the repository at this point in the history
Refs: #347
  • Loading branch information
LVMVRQUXL committed Feb 21, 2024
1 parent 6814abb commit c794026
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/commonMain/kotlin/kotools/types/number/StrictlyNegativeInt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ internal fun Int.isStrictlyNegative(): Boolean = this < 0
* involve rounding or truncation, or returns an encapsulated
* [IllegalArgumentException] if this number is [positive][PositiveInt].
*/
@OptIn(InternalKotoolsTypesApi::class)
@OptIn(ExperimentalKotoolsTypesApi::class, InternalKotoolsTypesApi::class)
@Since(KotoolsTypesVersion.V4_1_0)
public fun Number.toStrictlyNegativeInt(): Result<StrictlyNegativeInt> =
runCatching { StrictlyNegativeInt orFail this.toInt() }
runCatching(StrictlyNegativeInt.Companion::create)

/** Represents an integer number of type [Int] that is less than zero. */
@JvmInline
Expand Down Expand Up @@ -113,14 +113,6 @@ public value class StrictlyNegativeInt private constructor(
.takeIf(Int::isStrictlyNegative)
?.let(::StrictlyNegativeInt)

@InternalKotoolsTypesApi
@JvmSynthetic
internal infix fun orFail(value: Int): StrictlyNegativeInt {
val isValid: Boolean = value.isStrictlyNegative()
require(isValid) { value.shouldBeStrictlyNegative() }
return StrictlyNegativeInt(value)
}

/** Returns a random [StrictlyNegativeInt]. */
@Since(KotoolsTypesVersion.V3_0_0)
public fun random(): StrictlyNegativeInt = (min.value..max.value)
Expand Down

0 comments on commit c794026

Please sign in to comment.