Closed LVMVRQUXL closed 3 months ago
Internally, we could use the following pattern for validating inputs: ^[+-]?0+(?:[,.]0+)?$
(try it on RegExr).
Here are examples of valid inputs:
0
000000000 // multiple zeros
0.00 // dot as decimal point
0,0000 // comma as decimal point
+0 // unary plus
-0 // unary minus
The pattern used for validating inputs being an essential declaration that consumers should know when calling the factory functions of Zero
, it should be part of the public Application Programming Interface (API) with tests, documentation and samples.
The following overloads are not necessary for now, but they could be implemented by the community.
interface Zero {
companion object {
fun orNull(number: Short): Zero?
fun orNull(number: Int): Zero?
fun orNull(number: Long): Zero?
fun orNull(number: Float): Zero?
fun orNull(number: Double): Zero?
fun orThrow(number: Short): Zero
fun orThrow(number: Int): Zero
fun orThrow(number: Long): Zero
fun orThrow(number: Float): Zero
fun orThrow(number: Double): Zero
}
}
See the following issues:
π Description
For making usages of the
Zero
type more expressive, we want to add theorNull(Byte)
andorThrow(Byte)
experimental methods to theZero.Companion
type, for creating an instance ofZero
from the specifiednumber
.Here's the Application Programming Interface (API) goal of this issue:
These factory methods should be available for all platforms, except for the
orNull
method that shouldn't be accessible from Java, due to its non-explicit support for nullable types.Also, we should deprecate the
fromByte
and thefromByteOrNull
methods from theZero.Companion
experimental type with an error level for using those new factory functions.β Checklist
orThrow(Byte)
method for Kotlin and Java with tests, documentation and samples.orNull(Byte)
method only for Kotlin with tests, documentation and samples.fromByteOrNull
method with an error level for using theorNull
function instead.fromByte
method with an error level for using theorThrow
function instead.