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

add toStrictByteString #589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fumieval
Copy link
Contributor

This change saves the labour of having to import Data.ByteString.Lazy.toStrict just to obtain a strict ByteString.

@Bodigrim
Copy link
Contributor

This change saves the labour of having to import Data.ByteString.Lazy.toStrict just to obtain a strict ByteString.

toStrict is available from Data.ByteString as well, which is presumably already imported if you intend to work with strict bytestrings.

@fumieval
Copy link
Contributor Author

Oh, I hadn't realised that it is available since 0.11!

Still, I think it's a bit more convenient to have a strict counterpart in Data.ByteString.Builder.

@Bodigrim
Copy link
Contributor

Bodigrim commented Jun 4, 2023

I'm somewhat reluctant to add a trivial composition of toLazyByteString and toStrict under its own name; see haskell/text#295 (comment) for related discussion. @clyring what do you think?

@clyring
Copy link
Member

clyring commented Jun 4, 2023

I'm mildly in favor as far as API design goes.

L.toStrict . toLazyByteString is not the only reasonable implementation. (Accumulating chunks in reverse order and fixing that up at concatenation time would even save allocating a few thunks. But I'm not sure that's enough of an improvement to be worth providing.)

@Bodigrim
Copy link
Contributor

Bodigrim commented Jun 4, 2023

The thing is that if you want to build a StrictByteString you'd be better off using strict builders such as bytestring-strict-builder or text-builder-linear.

What happens in practice way too often is that a user does not really care about performance at all and just needs itoa :: Int -> StrictByteString, and the only way to implement it is Data.ByteString.toStrict . Data.ByteString.Builder.toLazyByteString . Data.ByteString.Builder.intDec. This is mouthful, I agree.

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 this pull request may close these issues.

3 participants