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

[core] Add numeric.NonNegInt #10

Closed
kevin-lee opened this issue Apr 26, 2023 · 0 comments · Fixed by #14
Closed

[core] Add numeric.NonNegInt #10

kevin-lee opened this issue Apr 26, 2023 · 0 comments · Fixed by #14
Assignees
Labels
Milestone

Comments

@kevin-lee
Copy link
Owner

kevin-lee commented Apr 26, 2023

Summary

[core] Add numeric.NonNegInt

Version

unreleased

Description

NonNegInt(1) // compiles
NonNegInt(0) // compiles
NonNegInt(-1) // compile-time error

NonNegInt.from(123)
// Either[String, NonNegInt] = Right(NonNegInt(123))

NonNegInt.from(-123)
// Either[String, NonNegInt] = Left(Invalid value: -123. It must be a non-negative Int)

NonNegInt.unsafeFrom(999)
// NonNegInt = NonNegInt(999)

NonNegInt.unsafeFrom(-999)
// IllegalArgumentException(Invalid value: -999. It must be a non-negative Int) is thrown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant