-
Notifications
You must be signed in to change notification settings - Fork 359
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
change String.toInt and String.toFloat to return Maybe instead of Result #558
Conversation
You need to also change the Elm files, not just the native files. |
d5bd877
to
1e2484c
Compare
@eeue56 yeah, you are right. Stupid me.. Now fixed. |
I also think adding some tests to https://github.com/elm-lang/core/blob/dev/tests/Test/String.elm might be worthwhile |
1e2484c
to
454277a
Compare
Done. |
I'd keep the Additionally But a String which can't be turned into a number isn't nothing, it's an error. This difference has to be reflected by the type. Since the |
@pisys can you provide list of potential errors which you see so far? |
The point is that a failng String-to-number conversion is an error and not nothing irrespective of how many or what kind of errors there could be. |
@gyzerok, @pisys, you both might want to take this discussion into account. Note also that that linked issue being closed does not mean it has been resolved. In fact, it lives on as an item in https://github.com/elm-lang/core/issues/322. That item's name is:
I don't think it makes much sense to have the discussion that you are having here, until that general item has been dealt with and been decided on (involving Evan). As a consequence, I'm inclined to close this PR here and to ask you to instead add mention of |
So, can I close here? |
Yeah, this may be the right thing, but the decision will happen at a different time. It's an easy change, so it's not vital for it to be done via PR. |
Whats done
Two little changes to the
String
module API.Why?
For more consistency of API with other core modules.
String
uncons : String -> Maybe (Char, String)
List
head : List a -> Maybe a
tail : List a -> Maybe (List a)
Dict
get : comparable -> Dict comparable v -> Maybe v
Personally I was confused when saw this first time. One may say that we can't get an actual error message with maybe, but there is only one possible error here. And you don't return error for example for while trying to get list head, it's just redundant.