Skip to content
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

headerContentID is not a valid Lens #76

Open
tomjaguarpaw opened this issue Dec 18, 2021 · 0 comments
Open

headerContentID is not a valid Lens #76

tomjaguarpaw opened this issue Dec 18, 2021 · 0 comments

Comments

@tomjaguarpaw
Copy link

It looks like headerContentID is not a valid Lens, because parse failure maps to Nothing, whilst setting Nothing removes the header in question from the list of headers. Thus set l (view l s) s = s is violated. Perhaps consider making it a Traversal' a ContentID instead?

> import Data.MIME
> import Data.IMF.Syntax
> import Data.String
> let l = headerContentID
> let s = Headers [(mk (fromString "Message-ID"), fromString "! unparseable !")]
> import Control.Lens
> set l (view l s) s
Headers []
> s
Headers [("Message-ID","! unparseable !")]

(Using Message-ID in this example because of #75)

headerContentID :: (HasHeaders a) => Lens' a (Maybe ContentID)
headerContentID = headers . at "Message-ID" . iso (>>= f) (fmap g)
where
f = either (const Nothing) Just . parseOnly (parseContentID <* endOfInput)
g = renderContentID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant