Reputation: 5642
I'm trying to see if a string is a valid integer using String.toInt strVar
, but I can't figure out how to translate the Result
to a Bool
.
Upvotes: 5
Views: 504
Reputation: 362
Just an update on this question. I use Elm 0.19 and things have changed a bit. Here the new code:
isIntParsable str =
case String.toInt str of
Just _ -> True
Nothing -> False
Currently String.toInt
returns a Maybe Int
.
Upvotes: 1
Reputation: 36030
You can pattern match the Result
.
If you want to get Bool as an output, then for example:
isIntParsable str =
case String.toInt str of
Ok _ -> True
_ -> False
Upvotes: 6