Skip to content

Commit

Permalink
♻️ Update StrictlyNegativeInt.Companion.createOrNull(Number) (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Feb 21, 2024
1 parent f2bb6e3 commit 73a6df4
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ public value class StrictlyNegativeInt private constructor(
@ExperimentalKotoolsTypesApi
@ExperimentalSince(KotoolsTypesVersion.Unreleased)
@JvmSynthetic
public fun createOrNull(number: Number): StrictlyNegativeInt? = number
.toInt()
.takeIf(Int::isStrictlyNegative)
?.let(::StrictlyNegativeInt)
public fun createOrNull(number: Number): StrictlyNegativeInt? {
val value: Int = number.toInt()
val isValid: Boolean = value.isStrictlyNegative()
return if (isValid) StrictlyNegativeInt(value) else null
}

/** Returns a random [StrictlyNegativeInt]. */
@Since(KotoolsTypesVersion.V3_0_0)
Expand Down

0 comments on commit 73a6df4

Please sign in to comment.