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

Expose fromStrict/toStrict from Data.ByteString #279

Closed
Bodigrim opened this issue Sep 5, 2020 · 2 comments · Fixed by #281
Closed

Expose fromStrict/toStrict from Data.ByteString #279

Bodigrim opened this issue Sep 5, 2020 · 2 comments · Fixed by #281
Milestone

Comments

@Bodigrim
Copy link
Contributor

Bodigrim commented Sep 5, 2020

I often end up importing Data.ByteString.Lazy just for the sake of fromStrict / toStrict. It would be nice to re-export these two functions from Data.ByteString itself.

@sjakobi
Copy link
Member

sjakobi commented Sep 7, 2020

Sounds reasonable to me.

@Bodigrim
Copy link
Contributor Author

Bodigrim commented Sep 7, 2020

Here is an example. My applications often deal with strict ByteString only:

import qualified Data.ByteString as B 

--- 100500 lines of code

foo :: ByteString
foo = B.replicate 99 99

However, if I need to pass foo to Data.Aeson.decode, which expects lazy ByteString, things get messy. I have to jump up to the imports and add import qualified Data.ByteString.Lazy as BL only to reach out for fromStrict. (And potentially change as B to as BS for consistency, which means a ton of minor edits all over the file). There are several workarounds, but the switch of context is very annoying.

import qualified Data.ByteString as BS 
import qualified Data.ByteString.Lazy as BL

bar = decode (BL.fromStrict foo)

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

Successfully merging a pull request may close this issue.

2 participants