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

Move parseInt and parseIntWithRadix from Float to Int module #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aspeddro
Copy link
Contributor

@aspeddro aspeddro commented Mar 2, 2023

  • Move parseInt and parseIntWithRadix to the Int module.
  • Add Int.isNaN because parseInt and parseIntWithRadix can return NaN

Todo:

  • Update CHANGELOG

Close #69

@cristianoc
Copy link
Contributor

NaN is not an int.
There's no type except float that captures the values returned by parseInt.
If moved to int, the function should be wrapped and adapted to e.g. return an optional, and not be zero-cost. Not sure if there's much value in doing that.

@glennsl
Copy link
Contributor

glennsl commented Mar 2, 2023

The parseInt and parseFloat functions are really quite bad, and I don't think they should even be used internally in Int.fromString and Float.fromString either. I've been thinking of opening an issue to discuss alternatives to it, but there aren't really any great alternatives either, so it requires a thorough exploration of the trade-offs.

@aspeddro
Copy link
Contributor Author

aspeddro commented Mar 3, 2023

Returning an option seems to be a good choice. Int.fromString already returns an option.

Some options:

  • Since parseInt and parseIntWithRadix accepts a generic we can remove Int.fromString
  • Rename Int.fromString to Int.parseInt (with optional ~radix parameter) and keep only one function. The current function Int.fromString doesn't make sense if we have parseInt and parseIntWithRadix

I think the parseInt and parseIntWithRadix functions should not accept a generic

@glennsl glennsl mentioned this pull request Mar 4, 2023
@glennsl
Copy link
Contributor

glennsl commented Mar 4, 2023

I've been thinking of opening an issue to discuss alternatives to it, but there aren't really any great alternatives either, so it requires a thorough exploration of the trade-offs.

See #86 for said issue.

@zth zth added this to the 0.3.0 milestone Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove parseInt and parseIntWithRadix from Float module
4 participants