Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New PositiveInt type in org.kotools.types package #637

Closed
1 of 14 tasks
LVMVRQUXL opened this issue Mar 31, 2024 · 5 comments
Closed
1 of 14 tasks

✨ New PositiveInt type in org.kotools.types package #637

LVMVRQUXL opened this issue Mar 31, 2024 · 5 comments
Labels
common Item related to all platforms. feature New feature or request.

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Mar 31, 2024

πŸ“ Description

We want to introduce a PositiveInt experimental type, in the org.kotools.types package of the types Gradle subproject, for representing an integer of type Int that is greater than zero. This type should be serializable as Int.

Here's the Application Programming Interface (API) goal for this type:

// In 'types' Gradle subproject:
interface PositiveInt {
    override fun equals(other: Any?): Boolean
    override fun hashCode(): Int
    fun toInt(): Int
    override fun toString(): String
    
    companion object {
        val min: PositiveInt
        val max: PositiveInt
        
        fun fromInt(number: Int): PositiveInt = TODO()
        fun fromIntOrNull(number: Int): PositiveInt? = TODO()
        
        fun random(): PositiveInt
    }
}

// In 'types-kotlinx-serialization' Gradle subproject:
val KotoolsTypesSerializers.positiveInt: SerializersModule

πŸ”— Dependencies

This issue is blocked by the following ones:

βœ… Checklist

  • ✨ Add the type with a private constructor and documentation.
  • ✨ Add the fromIntOrNull(Int) function with tests, documentation and samples.
  • ✨ Add the fromInt(Int) function with tests, documentation and samples.
  • ✨ Add the toInt() function with tests, documentation and samples.
  • ✨ Add the toString() function with tests, documentation and samples.
  • ✨ Add structural equality operations (equals(Any?) and hashCode() functions) with tests, documentation and samples.
  • ✨ Add the min property with tests, documentation and samples.
  • ✨ Add the max property with tests, documentation and samples.
  • ✨ Add the random() function with tests, documentation and samples.
  • ✨ Add the KotoolsTypesSerializers.positiveInt property for making this type serializable as Int.
  • πŸ“ Add an entry for this issue in the unreleased changelog.
  • πŸ“ Create an issue for introducing additional conversions with Byte and Short types.
  • πŸ’¬ Resolve comments of this issue.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Mar 31, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.6.0 milestone Mar 31, 2024
@LVMVRQUXL
Copy link
Contributor Author

LVMVRQUXL commented Mar 31, 2024

In the future, we could make instances of this type comparable with themselves and the integer types from the Kotlin standard library.

interface PositiveInt : Comparable<PositiveInteger> {
    operator fun compareTo(other: Byte): Int
    operator fun compareTo(other: Short): Int
    operator fun compareTo(other: Int): Int
    operator fun compareTo(other: Long): Int
    operator fun compareTo(other: PositiveInteger): Int
}

@LVMVRQUXL
Copy link
Contributor Author

LVMVRQUXL commented Mar 31, 2024

In the future, we could add support for basic arithmetic operations +, -, *, / and %.

@LVMVRQUXL
Copy link
Contributor Author

In the future, we could provide additional conversions for the PositiveInt.

interface PositiveInt {
    fun toByte(): Byte
    fun toShort(): Short
    fun toLong(): Long
    fun toFloat(): Float
    fun toDouble(): Double
}

@LVMVRQUXL

This comment was marked as outdated.

@LVMVRQUXL LVMVRQUXL changed the title ✨ New PositiveInteger type ✨ New PositiveInt type in org.kotools.types package May 3, 2024
@LVMVRQUXL LVMVRQUXL removed this from the 4.5.2 milestone May 8, 2024
@LVMVRQUXL
Copy link
Contributor Author

This type will be implemented internally for the PositiveInteger type (see issue #661).

@LVMVRQUXL LVMVRQUXL closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant