-
Notifications
You must be signed in to change notification settings - Fork 6
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
💡 The create
and createOrNull
factory functions
#587
Comments
Like pointed out by the Kotlin community on Reddit, it may be useful to define an overload of the Here's an example for the fun PositiveInt.Companion.create(number: Number, message: (Number) -> Any): PositiveInt Here's an example of calling this function from Kotlin code: val number: PositiveInt = PositiveInt.create(1) {
"$it should be greater than or equal to zero."
}
println(number) // 1 Here's the same example of calling this function, but from Java code: final PositiveInt result = PositiveInt.Companion.create(
1,
number -> number + " should be greater than or equal to zero."
);
System.out.println(result); // 1 If the specified PositiveInt.create(-1) { " " } // throws an IllegalArgumentException with a generic message
|
Like suggested by @lbunschoten in #335 (comment), we could mark these functions with the |
Ideas like that should be documented in GitHub Discussions instead. |
📝 Description
We would like to redesign our factory functions by introducing new
create
andcreateOrNull
factory functions for creating our stable types with the following behavior:create
functions should throw an exception in case of invalid inputscreateOrNull
functions should returnnull
in case of invalid inputs.Here's the goal of API that we should provide after completing this topic:
✅ Checklist
For the
StrictlyPositiveInt
type:StrictlyPositiveInt.Companion.create*
factory functions #342StrictlyPositiveInt.Companion.create
function with custom message #597StrictlyPositiveInt.Companion.create*
factory functions available on Java #438StrictlyPositiveInt.Companion.create*
factory functions #440toStrictlyPositiveInt
extension function with warning level #442toStrictlyPositiveInt
extension function to error level #443toStrictlyPositiveInt
extension function to hidden level #444toStrictlyPositiveInt
extension function #445toStrictlyPositiveInt
function inResultContext
with warning level #446toStrictlyPositiveInt
function inResultContext
to error level #447toStrictlyPositiveInt
function inResultContext
to hidden level #448toStrictlyPositiveInt
function inResultContext
#449For the
StrictlyNegativeInt
type:StrictlyNegativeInt.Companion.create*
factory functions #347StrictlyNegativeInt.Companion.create
function with custom message #598StrictlyNegativeInt.Companion.create*
factory functions available on Java #439StrictlyNegativeInt.Companion.create*
factory functions #441toStrictlyNegativeInt
extension function with warning level #450toStrictlyNegativeInt
extension function to error level #451toStrictlyNegativeInt
extension function to hidden level #452toStrictlyNegativeInt
extension function #453toStrictlyNegativeInt
function inResultContext
with warning level #454toStrictlyNegativeInt
function inResultContext
to error level #455toStrictlyNegativeInt
function inResultContext
to hidden level #456toStrictlyNegativeInt
function inResultContext
#457For the
PositiveInt
type:PositiveInt.Companion.create*
factory functions #349PositiveInt.Companion.create*
factory functions #458toPositiveInt
extension function with warning level #459toPositiveInt
extension function to error level #460toPositiveInt
extension function to hidden level #461toPositiveInt
extension function #462toPositiveInt
function inResultContext
with warning level #463toPositiveInt
function inResultContext
to error level #464toPositiveInt
function inResultContext
to hidden level #465toPositiveInt
function inResultContext
#466PositiveInt.Companion.create
function with custom messageFor the
NegativeInt
type:NegativeInt.Companion.create*
factory functions #350NegativeInt.Companion.create*
factory functions #467toNegativeInt
extension function with warning level #468toNegativeInt
extension function to error level #469toNegativeInt
extension function to hidden level #470toNegativeInt
extension function #471toNegativeInt
function inResultContext
with warning level #472toNegativeInt
function inResultContext
to error level #473toNegativeInt
function inResultContext
to hidden level #474toNegativeInt
function inResultContext
#475NegativeInt.Companion.create
function with custom messageFor the
NonZeroInt
type:NonZeroInt.Companion.create*
factory functions #351NonZeroInt.Companion.create*
factory functions #476toNonZeroInt
extension function with warning level #477toNonZeroInt
extension function to error level #478toNonZeroInt
extension function to hidden level #479toNonZeroInt
extension function #480toNonZeroInt
function inResultContext
with warning level #481toNonZeroInt
function inResultContext
to error level #482toNonZeroInt
function inResultContext
to hidden level #483toNonZeroInt
function inResultContext
#484NonZeroInt.Companion.create
function with custom messageFor the
NotBlankString
type:NotBlankString.Companion.create*
factory functions #341NotBlankString.Companion.create*
functions #541NotBlankString.Companion.create*
functions available on Java #412NotBlankString.Companion.create*
factory functions #395toNotBlankString
extension function #396toNotBlankString
extension function to error level #397toNotBlankString
extension function to hidden level #398toNotBlankString
extension function #399toNotBlankString
function inResultContext
#400toNotBlankString
function inResultContext
to error level #401toNotBlankString
function inResultContext
to hidden level #402toNotBlankString
function inResultContext
#403NotBlankString.Companion.create
function with custom messageFor the
NotEmptyList
type:NotEmptyList.Companion
#352NotEmptyList.Companion
available on Java #497NotEmptyList
#498notEmptyListOf
function with warning level #499notEmptyListOf
function to error level #500notEmptyListOf
function to hidden level #501notEmptyListOf
function #502toNotEmptyList
extension function with warning level #503toNotEmptyList
extension function to error level #504toNotEmptyList
extension function to hidden level #505toNotEmptyList
extension function #506toNotEmptyList
function inResultContext
with warning level #507toNotEmptyList
function inResultContext
to error level #508toNotEmptyList
function inResultContext
to hidden level #509toNotEmptyList
function inResultContext
#510NotEmptyList.Companion.create
function with custom messageFor the
NotEmptySet
type:NotEmptySet.Companion
#353NotEmptySet.Companion
available on Java #511NotEmptySet.Companion
type #512notEmptySetOf
function with warning level #513notEmptySetOf
function to error level #514notEmptySetOf
function to hidden level #515notEmptySetOf
function #516toNotEmptySet
extension function with warning level #517toNotEmptySet
extension function to error level #518toNotEmptySet
extension function to hidden level #519toNotEmptySet
extension function #520toNotEmptySet
function ofResultContext
type with warning level #521toNotEmptySet
function ofResultContext
type to error level #522toNotEmptySet
function ofResultContext
type to hidden level #523toNotEmptySet
function ofResultContext
type #524NotEmptySet.Companion.create
function with custom messageFor the
NotEmptyMap
type:NotEmptyMap.Companion
#354NotEmptyMap.Companion
available on Java #525NotEmptyMap.Companion
's factory functions #526notEmptyMapOf
function with warning level #527notEmptyMapOf
function to error level #528notEmptyMapOf
function to hidden level #529notEmptyMapOf
function #530toNotEmptyMap
extension function with warning level #531toNotEmptyMap
extension function to error level #532toNotEmptyMap
extension function to hidden level #533toNotEmptyMap
extension function #534NotEmptyMap.Companion.create
function with custom messageThe text was updated successfully, but these errors were encountered: