Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upNonEmptyString type to handle empty string cases in the code #697
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Aug 23, 2016
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Aug 23, 2016
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Aug 23, 2016
Member
I think it makes sense to do more discussion on Elm Slack or elm-discuss before having an issue here about it.
I often use languages with a NonEmptyList type and it's never been worth the trouble in my experience. I.e. I've never had a bug related to doing this wrong.
One way to handle your case is to make a special type:
type UserName = Known String | Unknown
user : String -> Result String UserNameAnd you can have the user function check that everything is valid. If the internal details of User are hidden, no one on the outside can ever modify the name, so you know that all User data is good and only have to check once.
In any case, makes sense to continue on elm-discuss or Slack.
|
I think it makes sense to do more discussion on Elm Slack or elm-discuss before having an issue here about it. I often use languages with a One way to handle your case is to make a special type: type UserName = Known String | Unknown
user : String -> Result String UserNameAnd you can have the In any case, makes sense to continue on elm-discuss or Slack. |
ondrejsevcik commentedAug 23, 2016
Hi, sometimes I have to treat an empty string as an invalid state (e.g. in Username) and in those cases, I have to check for all occurrences in my code and make sure that there is proper check for an empty string value.
It would be really great if the compiler could do all the checks for me. I thought about
NonEmptyStringtype that would always contain some characters.then I could define my
usernametoMaybe NonEmptyStringand the compiler will make sure that all the cases are handled in my code.What do you think about it?
How do you currently solve this issue in your code?