Skip to content

Add map function for byte arrays#6

Merged
jappeace merged 1 commit intojappeace:masterfrom
jappeace-sloth:add-map-function
Mar 27, 2026
Merged

Add map function for byte arrays#6
jappeace merged 1 commit intojappeace:masterfrom
jappeace-sloth:add-map-function

Conversation

@jappeace-sloth
Copy link
Copy Markdown

Summary

  • Adds map :: (ByteArrayAccess ba, ByteArray ba) => (Word8 -> Word8) -> ba -> ba to Data.ByteArray.Methods (re-exported via Data.ByteArray), as requested in map #5
  • Uses copyAndFreeze to copy the array then mutate each byte in-place
  • Bumps version to 0.22.0
  • Adds QuickCheck property test verifying B.map f == B.pack . Prelude.map f . B.unpack

Closes #5

Test plan

  • cabal build passes with no new warnings
  • cabal test — all 278 tests pass (including new map test for both Bytes and ScrubbedBytes backends)
  • nix-build nix/ci.nix succeeds
  • New test verified to fail on master (compile error: B.map not in scope)

🤖 Generated with Claude Code

Add `map :: (ByteArrayAccess ba, ByteArray ba) => (Word8 -> Word8) -> ba -> ba`
to Data.ByteArray.Methods, which applies a function to each byte of a byte
array. Uses copyAndFreeze to copy the array then modify each byte in-place.
Bump version to 0.22.0. QuickCheck property test verifies equivalence with
Prelude.map on unpacked bytes.

Prompt: implement this issue for ram: jappeace#5
find a good place to put it into jappeace/ram bump the version, write a test
to verify it works too

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jappeace
Copy link
Copy Markdown
Owner

@kazu-yamamoto please review if this is what you want ^

@kazu-yamamoto
Copy link
Copy Markdown

LGTM.

Since this is just an addition, I initially thought the version should be 0.21.2. However, the name map"conflicts with Prelude.map. To be safe, I support version 0.22.0.

I will probably ask two more additions.

@kazu-yamamoto
Copy link
Copy Markdown

Making ScrubbedBytes to be an instance of Generic (for serialization) failed.
So, I should ask one more thing.

@jappeace jappeace merged commit b6f9f28 into jappeace:master Mar 27, 2026
16 checks passed
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.

map

3 participants