Offer an 'optional' combinator #53

Open
ocharles opened this Issue Nov 29, 2012 · 2 comments

Projects

None yet

3 participants

@ocharles
Contributor

It would be much more elegant if we could have an optional combinator. This would both clean up the API (no need to offer stringRead and optionalStringRead), while also providing nicer code for authors. For example, at the moment I have:

  where labelCode = check "Label codes must be positive and at most 5 digits"
                      (maybe True (\i -> i > 0 && i < 100000)) $
                        optionalStringRead "Invalid integer" Nothing

Which is a tad on the messy side (I have to handle Maybe inside that check).

@jaspervdj
Owner

This is also what I originally wanted to do, but I couldn't come up with a good implementation and semantics that make sense. The problem is that it's extremely tricky for composed forms...

@LukeHoersten
Contributor

Here's my excessively copy-paste use case: https://gist.github.com/LukeHoersten/7896241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment