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 type converters suffixed by OrNull and OrThrow for PositiveInt #155

Closed
20 tasks done
LVMVRQUXL opened this issue Jul 31, 2023 · 0 comments · Fixed by #236
Closed
20 tasks done

New type converters suffixed by OrNull and OrThrow for PositiveInt #155

LVMVRQUXL opened this issue Jul 31, 2023 · 0 comments · Fixed by #236
Assignees
Labels
common Item related to all platforms. feature New feature or request.
Milestone

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Jul 31, 2023

Description

Like discussed in #104, we would like to introduce experimental builders for the PositiveInt type that should:

  • return null in case of a failure if the builder is suffixed by OrNull
  • throw an IllegalArgumentException in case of a failure if the builder is suffixed by OrThrow.

These builders should work on all platforms and should be declared in the PositiveInt.kt file after the toPositiveInt function.
Their tests should be declared in the PositiveIntTest class after the number_toPositiveInt_should_fail_with_a_strictly_negative_Int function.

Checklist

Function signatures
/**
 * Returns this number as a [PositiveInt], which may involve rounding or
 * truncation, or returns `null` if this number is
 * [strictly negative][StrictlyNegativeInt].
 *
 * Here's some usage examples:
 *
 * ```kotlin
 * var result: PositiveInt? = 1.toPositiveIntOrNull()
 * println(result) // 1
 *
 * result = 0.toPositiveIntOrNull()
 * println(result) // 0
 *
 * result = (-1).toPositiveIntOrNull()
 * println(result) // null
 * ```
 *
 * You can use the [toPositiveIntOrThrow] function for throwing an
 * [IllegalArgumentException] instead of returning `null` when this number is
 * [strictly negative][StrictlyNegativeInt].
 */
@ExperimentalNumberApi
@ExperimentalSinceKotoolsTypes("4.3.1")
public fun Number.toPositiveIntOrNull(): PositiveInt? {
    TODO()
}

/**
 * Returns this number as a [PositiveInt], which may involve rounding or
 * truncation, or throws [IllegalArgumentException] if this number is
 * [strictly negative][StrictlyNegativeInt].
 *
 * Here's some usage examples:
 *
 * ```kotlin
 * var result: PositiveInt = 1.toPositiveIntOrThrow()
 * println(result) // 1
 *
 * result = 0.toPositiveIntOrThrow()
 * println(result) // 0
 *
 * (-1).toPositiveIntOrThrow() // IllegalArgumentException
 * ```
 *
 * You can use the [toPositiveIntOrNull] function for returning `null` instead
 * of throwing an [IllegalArgumentException] when this number is
 * [strictly negative][StrictlyNegativeInt].
 */
@ExperimentalNumberApi
@ExperimentalSinceKotoolsTypes("4.3.1")
public fun Number.toPositiveIntOrThrow(): PositiveInt {
    TODO()
}
Entry in changelog
### Added

**Experimental** builders suffixed by `OrNull` and `OrThrow` for the following
types:
- `PositiveInt` (issue [#155] implemented by [@YourGitHubProfile](#)).

[#155]: https://github.com/kotools/types/issues/155
Commit message
feat(#155): add experimental builders for 'PositiveInt'

New builders: 'toPositiveIntOrNull' and 'toPositiveIntOrThrow'.
These are not implemented yet.
  • Implement the toPositiveIntOrNull function by resolving the following tasks:
    • Add unit tests for this new function.
    • Run tests on the JVM platform. These should fail at this stage.
    • Implement this new function without changing its signature.
    • Run tests on the JVM platform. These should pass at this stage.
    • Commit your local changes by running the git commit -a command in your terminal with the message below.
Commit message
feat(#155): implement the 'toPositiveIntOrNull' function
  • Implement the toPositiveIntOrThrow function by resolving the following tasks:
    • Add unit tests for this new function.
    • Run tests on the JVM platform. These should fail at this stage.
    • Implement this new function without changing its signature.
    • Run tests on the JVM platform. These should pass at this stage.
    • Commit your local changes by running the git commit -a command in your terminal with the message below.
Commit message
feat(#155): implement the 'toPositiveIntOrThrow' function

Maintainers only

  • Refactor the construction of the type by using functional programming tools provided by Kotlin for improving its readability, composability and performance.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Jul 31, 2023
@LVMVRQUXL LVMVRQUXL added this to the 4.3.0 milestone Jul 31, 2023
@LVMVRQUXL LVMVRQUXL self-assigned this Jul 31, 2023
@LVMVRQUXL LVMVRQUXL changed the title New builders suffixed by OrElse, OrNull and OrThrow for PositiveInt New builders suffixed by OrNull and OrThrow for PositiveInt Aug 2, 2023
@LVMVRQUXL LVMVRQUXL modified the milestones: 4.3.0, 4.4.0 Aug 3, 2023
@LVMVRQUXL LVMVRQUXL removed their assignment Aug 12, 2023
@LVMVRQUXL LVMVRQUXL added the good first issue Issues having enough details for new contributors to work on. label Aug 12, 2023
@LVMVRQUXL LVMVRQUXL added good first issue Issues having enough details for new contributors to work on. and removed good first issue Issues having enough details for new contributors to work on. labels Sep 1, 2023
@LVMVRQUXL LVMVRQUXL modified the milestones: 4.4.0, 4.3.1 Sep 3, 2023
@LVMVRQUXL LVMVRQUXL self-assigned this Sep 21, 2023
@LVMVRQUXL LVMVRQUXL removed the good first issue Issues having enough details for new contributors to work on. label Sep 21, 2023
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
New builders: 'toPositiveIntOrNull' and 'toPositiveIntOrThrow'.
These are not implemented yet.
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
New builders: 'toPositiveIntOrNull' and 'toPositiveIntOrThrow'.
These are not implemented yet.
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
New builders: 'toPositiveIntOrNull' and 'toPositiveIntOrThrow'.
These are not implemented yet.
LVMVRQUXL added a commit that referenced this issue Sep 21, 2023
@LVMVRQUXL LVMVRQUXL changed the title New builders suffixed by OrNull and OrThrow for PositiveInt New type converters suffixed by OrNull and OrThrow for PositiveInt Oct 22, 2023
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

Successfully merging a pull request may close this issue.

1 participant