types icon indicating copy to clipboard operation
types copied to clipboard

✨ New `Integer` 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 Integer experimental interface for representing an integer. 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 Zero and the NonZeroInteger types should implement this interface.

interface Integer {
    companion object {
        fun orNull(number: Int): Integer? = TODO()
        fun orNull(number: Long): Integer? = TODO()

        fun orThrow(number: Int): Integer = TODO()
        fun orThrow(number: Long): Integer = TODO()
    }
}

interface Zero : Integer
interface NonZeroInteger : Integer

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

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

🔗 Dependencies

This issue is blocked by the following items:

  • [x] #644
  • [ ] #825

✅ Checklist

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

  • [ ] ✨ Add the Integer interface with documentation.
  • [ ] ✨ Make the Zero type implementing the Integer interface.
  • [ ] ✨ Make the NonZeroInteger type implementing the Integer interface.
  • [ ] ✨ Add the Integer.Companion.orNull(Int) function with tests, documentation and samples.
  • [ ] ✨ Add the Integer.Companion.orNull(Long) function with tests, documentation and samples.
  • [ ] ✨ Add the Integer.Companion.orThrow(Int) function with tests, documentation and samples.
  • [ ] ✨ Add the Integer.Companion.orThrow(Long) function with tests, documentation and samples.
  • [ ] ✨ Add the Integer.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 23 '25 09:04 LVMVRQUXL