types icon indicating copy to clipboard operation
types copied to clipboard

✨ New `NonZeroInteger` type

Open LVMVRQUXL opened this issue 6 months ago • 0 comments
trafficstars

📝 Description

In the org.kotools.types package of the types Gradle subproject, we want to add the NonZeroInteger experimental interface for representing an integer that is other than zero. This interface should be available for all Kotlin platforms and Java, but its orNull functions shouldn't be available from Java, due to its its non-explicit support for nullable types.

Also, the PositiveInteger and the NegativeInteger types should implement this interface.

interface NonZeroInteger {
    companion object {
        fun orNull(number: Int): NonZeroInteger? = TODO()
        fun orNull(number: Long): NonZeroInteger? = TODO()
        
        fun orThrow(number: Int): NonZeroInteger = TODO()
        fun orThrow(number: Long): NonZeroInteger = TODO()
    }
}

interface PositiveInteger
interface NegativeInteger

Finally, in the types-kotlinx-serialization subproject, we want to add the NonZeroInteger.Companion.stringSerializer() experimental function for serializing the NonZeroInteger type as String. This function should be only available for Kotlin platforms.

fun NonZeroInteger.Companion.stringSerializer(): KSerializer<NonZeroInteger>

🔗 Dependencies

This issue is blocked by the following items:

  • [ ] #661
  • [ ] #821

✅ Checklist

See the Issue implementation section in the contributing guidelines before addressing the following checklist.

  • [ ] ✨ Add the NonZeroInteger interface with documentation.
  • [ ] ✨ Make the PositiveInteger type implementing the NonZeroInteger interface.
  • [ ] ✨ Make the NegativeInteger type implementing the NonZeroInteger interface.
  • [ ] ✨ Add the NonZeroInteger.Companion.orNull(Int) function with tests, documentation and samples.
  • [ ] ✨ Add the NonZeroInteger.Companion.orNull(Long) function with tests, documentation and samples.
  • [ ] ✨ Add the NonZeroInteger.Companion.orThrow(Int) function with tests, documentation and samples.
  • [ ] ✨ Add the NonZeroInteger.Companion.orThrow(Long) function with tests, documentation and samples.
  • [ ] ✨ Add the NonZeroInteger.Companion.stringSerializer() function with tests, documentation and samples.
  • [ ] 📝 Update the unreleased changelog for this issue.
  • [ ] 📝 After closing this issue, update the status of tracking issues depending only on this one.

LVMVRQUXL avatar Apr 24 '25 09:04 LVMVRQUXL