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

Difficult to introduce fallbacks when parseQuality fails #20

Closed
Zankoku-Okuno opened this issue Jan 6, 2017 · 6 comments
Closed

Difficult to introduce fallbacks when parseQuality fails #20

Zankoku-Okuno opened this issue Jan 6, 2017 · 6 comments
Assignees

Comments

@Zankoku-Okuno
Copy link
Contributor

In #1, I suggested that some sort of a -> Float -> Quality a function was unnecessary, but now that I'm using this library more, I think that was a poor idea, mainly for this reason:

fromMaybe (fromJust $ parseQuality "*/*") $
    parseQuality =<< lookup "Accept" (Wai.requestHeaders req)

Or in English, when there is no Accept header (or it's invalid), then I want to behave as if the client will accept anything. The code above is a workaround, but while I know the fromJust will work, I've developed a special enmity towards this particular partial function. It would be much better to replace (fromJust $ ...) with something like ("*/*" `q` 1) (though probably q isn't the best name... but I'll let you sort that out).

And, to answer the question from #1 about a fractional vs. integral argument, I think the fractional is the clearest. After all, if it's written 0.8 in the header, it may as well be written 0.8 in Haskell.

@zmthy
Copy link
Owner

zmthy commented Jan 6, 2017

Okay. I think I might actually just make the argument a string and reuse readQ. I won't have time to get on top of this for at least two weeks but it should be a pretty simple addition.

@zmthy zmthy self-assigned this Jan 22, 2017
@zmthy
Copy link
Owner

zmthy commented Jan 22, 2017

Are you ever building quality values that don't have a quality of 1?

@Zankoku-Okuno
Copy link
Contributor Author

Re building non-1 quality values: I think it's possible. My current use-case can afford to be a toy, but I could easily see someone building a server that fills in a default accept header along the lines of text/html,*/*;q=0.9.

@zmthy
Copy link
Owner

zmthy commented Jan 23, 2017

Okay, I've pushed to develop. I've exposed the maxQuality and minQuality functions, as well as a new quality function that uses readQ with a default error message. I've also prepped to bump the version to 1.0, let me know what you think and I'll finalise the release and publish to Hackage.

@zmthy
Copy link
Owner

zmthy commented May 29, 2017

Totally forgot about this. Let me know if you have any thoughts, I'll push the release soon.

@Zankoku-Okuno
Copy link
Contributor Author

Well, you're not alone in forgetting :)

I think this kills the issue. I was going back-and-forth on whether an IsString instance would be good, but IsString a => IsString (Quality a) seems way too general to be a good idea.

I did have an unrelated idea before you publish, which I've put in #21 for organization purposes.

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

No branches or pull requests

2 participants