-
Notifications
You must be signed in to change notification settings - Fork 42
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 LenientData #45
Add LenientData #45
Conversation
Ok, what options do we have here? So far I see these:
I like option 3 the most. Because Option 2 is bad because of What I would do is rather use type API = LenientQueryParam "param" MyParam This would allow us to have type API = RequiredLenientQueryParam "param" MyParam Which would result in If Servant were to implement |
I'm 👍 with your plan, so the |
I'm otherwise ok with this PR, are you going to add anything else here or should I merge it already? |
I'll add few instances, |
@fizruk,I'd say this is ready. Even we won't need |
foldMap f (LenientData (Right x)) = f x | ||
|
||
instance Traversable LenientData where | ||
traverse f (LenientData x) = fmap LenientData (traverse f x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you just derive Functor
, Foldable
and Traversable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoderivied all of them
|
||
-- | Lenient parameters. 'FromHttpApiData' combinators always return `Right`. | ||
newtype LenientData a = LenientData { getLenientData :: Either Text a } | ||
deriving (Eq, Ord, Show, Read, Typeable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you also derive Data
?
Nice, thanks! |
Motivated by
servant
making parameter parsing fail.Is it ok to define
ToHttpApiData
instance withtoQueryParam = either (const "") toQueryParam . getLenientData
, i.e. serialisingLeft
to an empty string?