add toStrictByteString
This change saves the labour of having to import Data.ByteString.Lazy.toStrict just to obtain a strict ByteString.
This change saves the labour of having to import
Data.ByteString.Lazy.toStrictjust 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.
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.
I'm somewhat reluctant to add a trivial composition of toLazyByteString and toStrict under its own name; see https://github.com/haskell/text/pull/295#issuecomment-680165743 for related discussion. @clyring what do you think?
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.)
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.