Add slice and unsafeSlice for ByteArray#8
Conversation
- slice: extracts sub-range [start, end) with Word indices, returns Maybe (Nothing when indices exceed length) - unsafeSlice: same but clamps out-of-bounds indices to valid range - Both swap indices if end < start - Added property tests: equivalence with take/drop, out-of-bounds returns Nothing, clamping behaviour, and index swap symmetry Prompt: Implement the plan to add slice/unsafeSlice to ram (issue jappeace#7) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@kazu-yamamoto please review this as well, see if it's like how you expect |
|
Just a moment. |
|
Two minor observations:
The For example, I found the length to be more clear in meaning. |
|
I guess that |
…or on invalid - Change slice/unsafeSlice signatures from Word to Int - Change from (start, end) to (offset, length) semantics - unsafeSlice now calls error instead of clamping on invalid args - slice returns Nothing for negative offset/length or out-of-bounds - Update tests: new semantics, negative input tests, error assertion - Update CHANGELOG entry Addresses review comments from kazu-yamamoto on PR jappeace#8. Prompt: Implement the following plan: Address PR jappeace#8 review comments Tokens: ~40k input, ~8k output Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@kazu-yamamoto I changed it according to your suggestions, please review if this is better for you? |
|
Very good. |
|
If you release a new version, I will also release |
|
yeah it's released: https://hackage.haskell.org/package/ram |
Summary
slice :: ByteArray bs => bs -> Word -> Word -> Maybe bs— extracts sub-range[start, end), returnsNothingwhen indices exceed lengthunsafeSlice :: ByteArray bs => bs -> Word -> Word -> bs— same but clamps out-of-bounds indicesend < startTest plan
slicematchestake (end-start) . drop startNothingunsafeSliceclamps to valid rangeslice a b == slice b a(swap symmetry)BytesandScrubbedBytesbackendsnix-build nix/ci.nixpasses🤖 Generated with Claude Code