-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add reference to Integer.parse/2 in String.to_integer/1 #7924
Add reference to Integer.parse/2 in String.to_integer/1 #7924
Conversation
This should reduce confusion for newcomers about how function works and what to use when you need to gracefully handle possible ill-formated strings.
lib/elixir/lib/string.ex
Outdated
@@ -2186,13 +2186,20 @@ defmodule String do | |||
@doc """ | |||
Returns an integer whose text representation is `string`. | |||
|
|||
`string` must be the string representation of a integer. In order to parse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“of an integer”
lib/elixir/lib/string.ex
Outdated
Inlined by the compiler. | ||
|
||
## Examples | ||
|
||
iex> String.to_integer("123") | ||
123 | ||
|
||
String.to_integer("invalid data") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use iex>
here https://hexdocs.pm/ex_unit/ExUnit.DocTest.html#module-exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, and the problem is that compiler will catch that as this will always fail and it will produce compiler warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hauleth you can try "hiding" the input.
iex> String.to_integer(List.to_string(["123", "invalid"]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think that would make the documentation a bit hard to understand, and I think that should be the focus (not the actual doctest). So I'm 👍 for the #=>
solution.
@whatyouhide apparently changing the String module via the GitHub UI has normalized UTF-8 strings and changed the module semantics. 😱 |
My screw up is harder to fix than I expected 😅 @hauleth, would you mind closing this PR and opening a new one with the same changes (plus the small change in my commit, which just adds an "an")? Sorry for the inconvenience :) |
@whatyouhide I can force push my changes. I will fix this one ;) |
ad4885b
to
6f1b161
Compare
@whatyouhide done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing it @hauleth! 😄
lib/elixir/lib/string.ex
Outdated
Inlined by the compiler. | ||
|
||
## Examples | ||
|
||
iex> String.to_integer("123") | ||
123 | ||
|
||
String.to_integer("invalid data") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think that would make the documentation a bit hard to understand, and I think that should be the focus (not the actual doctest). So I'm 👍 for the #=>
solution.
❤️ 💚 💙 💛 💜 |
This should reduce confusion for newcomers about how function works and
what to use when you need to gracefully handle possible ill-formated
strings.