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 StrictlyNegativeInt.Companion.create function with custom message #598

Closed
2 tasks
Tracked by #587 ...
LVMVRQUXL opened this issue Mar 21, 2024 · 0 comments
Closed
2 tasks
Tracked by #587 ...
Labels
common Item related to all platforms. feature New feature or request.

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Mar 21, 2024

📝 Description

We would like to introduce an experimental StrictlyNegativeInt.Companion.create function for accepting a customized exception message.

fun StrictlyNegativeInt.Companion.create(
    number: Number,
    message: (Number) -> Any
): StrictlyNegativeInt

This function throws an IllegalArgumentException with the specified message if the specified number is greater than or equals zero. If the message has a blank string representation, it throws the exception with a generic message instead.

Here are some examples of calling this function from Kotlin code:

println(StrictlyNegativeInt.create(-1) { "$it should be less than zero." }) // -1
StrictlyNegativeInt.create(0) { "$it should be less than zero." } // throws an exception with the specified message
StrictlyNegativeInt.create(-1) { " " } // throws an exception with a generic message

The StrictlyNegativeInt type being an inline value class, this function shouldn't be available yet for Java users.

✅ Checklist

  • Add this declaration, test its behavior with Kotlin, update the public API binaries and update the unreleased changelog.
  • Close this issue as completed and update tracking ones if present.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Mar 21, 2024
@LVMVRQUXL LVMVRQUXL closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 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