Repository navigation
Add runPutMBuilder - #249
Open
NopeCharon wants to merge 2 commits into
Open
NopeCharon wants to merge 2 commits into
NopeCharon wants to merge 2 commits into
Conversation
There was no way to run a PutM computation and get both its result and
the Builder it constructed in a single call: runPutM executes the
Builder into a lazy ByteString, execPut discards the result, and the
PairS type that holds both is not exported. This makes it awkward to
embed PutM computations into larger Builder-based writers while still
using their results.
Add
runPutMBuilder :: PutM a -> (a, Builder)
which returns the result together with the unexecuted Builder, so it
can be combined with other Builders. The name matches the equivalent
function in cereal, as suggested in the issue.
Add a QuickCheck property checking that the result and the bytes agree
with runPutM, that the Builder composes, and that the Builder of an
infinite PutM is returned without being run.
Closes haskell#151
konsumlamm
reviewed
Dec 5, 2026
Comment on lines
+945
to
+946
| -- the Builder is returned without being run | ||
| , L.take 16 (Builder.toLazyByteString (snd (runPutMBuilder infPut))) === L.replicate 16 w8 |
Contributor
There was a problem hiding this comment.
How does this check that the Builder is returned without being run?
Author
There was a problem hiding this comment.
It doesn't, really. It only shows that an infinite PutM still streams through runPutMBuilder, which running the Builder lazily would pass too, so I reworded the comment in da58d7b to say just that.
The comment claimed the assertion shows the Builder is returned without being run, but taking a prefix of an infinite PutM only shows that runPutMBuilder does not force the Builder, so the output still streams. Running the Builder lazily and re-wrapping the bytes would pass as well. Reword the comment to describe what is actually checked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #151.
Adds
to
Data.Binary.Put. It returns the result of aPutMcomputation together with theBuilderit constructed, without running theBuilder(unlikerunPutM), so the computation can be embedded in a largerBuilder-based writer while still using its result. Previously there was no single function for this, sincePairSisn't exported.I went with
cereal's name, as mentioned in the issue. I'm happy to rename it if you prefer something else.Tests: a QuickCheck property checking that the result and bytes match
runPutM, that the returnedBuildercomposes, and that an infinitePutMstill streams throughrunPutMBuilder.