-
Notifications
You must be signed in to change notification settings - Fork 102
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 getPropOrError to crocks #509
Comments
I think if we were to implement this, we'd want to match What may help here is some example use cases as well, think "what would i want to put in the docs?" |
@dalefrancis88 Quick response! I see your point, however I see the function more akin to My use cases are often around pulling props out of config objects, JSON responses from an API (where according to the contract the prop is mandatory), etc. Anywhere where the program can't continue because it's missing mandatory input. For example:
So if the On a related note, something that's confused me a bit when using HM is whether to use For example, shouldn't |
so to answer the On the main point, I would see this as equiv to
|
Thanks for the explanation. That's what my current understanding is. It's more a question of why have functions been typed to work on "anything" rather than
Fair point, however I wouldn't find that as useful, because I want the message to be consistent everywhere without me having to specify it. So I'd have to do either:
(2) isn't completely fuggly and it would allow |
@kierans given that some time has past, how do you feel about this suggestion, does it still stand? Have you had any further insights that might help with this? |
@dalefrancis88 I haven't been doing much with Crocks lately as I've been doing other work. However I'm coming back to it. I don't have new insights, but rereading the comments above, I still agree with past me. It just depends on whether you/others feel this is a worthwhile addition to the Crocks standard library. |
Is your feature request related to a problem? Please describe.
I'm on my fourth project using Crocks and I keep reaching for the same function
getPropOrError
(andgetPathOrError
). Instead of me releasing my own library, or copy/pasting the function around I think it would be good to have this in the standard library.Describe the solution you'd like
getPropOrError :: String -> a -> Result Error b
getPathOrError :: [ String ] -> a -> Result Error b
Describe alternatives for how you do this now
Doing a
maybeToResult
ongetProp
with anError
ifgetProp
returns aNothing.
Code
Do you have example code or tests in a Repl for what you'd like added?
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: