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 NonZeroInt #173

Closed
20 tasks done
LVMVRQUXL opened this issue Aug 20, 2023 · 1 comment
Closed
20 tasks done
Assignees
Labels
common Item related to all platforms. feature New feature or request.
Milestone

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Aug 20, 2023

Description

Like discussed in #104, we would like to introduce experimental builders for the NonZeroInt 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 NonZeroInt.kt file after the toNonZeroInt function.
Their tests should be declared in the NonZeroIntTest class after the number_toNonZeroInt_should_fail_with_an_Int_that_equals_zero function.

Checklist

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

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

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

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

New builders: 'toNonZeroIntOrNull' and 'toNonZeroIntOrThrow'.
These are not implemented yet.
  • Implement the toNonZeroIntOrNull 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(#173): implement the 'toNonZeroIntOrNull' function
  • Implement the toNonZeroIntOrThrow 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(#173): implement the 'toNonZeroIntOrThrow' 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 Aug 20, 2023
@LVMVRQUXL LVMVRQUXL added this to the 4.4.0 milestone Aug 20, 2023
@LVMVRQUXL LVMVRQUXL self-assigned this Aug 20, 2023
@LVMVRQUXL LVMVRQUXL added the good first issue Issues having enough details for new contributors to work on. label Aug 20, 2023
@LVMVRQUXL LVMVRQUXL removed their assignment Aug 20, 2023
@LVMVRQUXL LVMVRQUXL mentioned this issue Aug 20, 2023
9 tasks
@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: 'toNonZeroIntOrNull' and 'toNonZeroIntOrThrow'.
These are not implemented yet.
@LVMVRQUXL
Copy link
Contributor Author

Done.

@LVMVRQUXL LVMVRQUXL changed the title New builders suffixed by OrNull and OrThrow for NonZeroInt New type converters suffixed by OrNull and OrThrow for NonZeroInt 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

No branches or pull requests

1 participant