Skip to content

🐛 Allow SequenceSet#slice length to be zero - #781

Merged
nevans merged 1 commit into
masterfrom
sequence_set/fix-slice-with-zero-length
Oct 10, 2026
Merged

nevans merged 1 commit into
masterfrom
sequence_set/fix-slice-with-zero-length

Conversation

@nevans

@nevans nevans commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

When length is zero, #slice will behave similarly to Array#slice: it returns an empty set when starting index is in range and nil when the starting index is out of range.

But, "in range" is defined as start.abs <= cardinality, which includes start == cardinality. So:

set[set.cardinality]        => nil
set[set.cardinality..]      => SequenceSet.empty
set[set.cardinality.succ..] => nil

When length is zero, `#slice` will behave similarly to `Array#slice`:
it returns an empty set when starting index is in range and `nil` when
the starting index is out of range.

But, "in range" is defined as `start.abs <= cardinality`, which includes
`start == cardinality`.  So:
```ruby
set[set.cardinality]        => nil
set[set.cardinality..]      => SequenceSet.empty
set[set.cardinality.succ..] => nil
```
@nevans
nevans added this pull request to stack #775 October 10, 2026 03:16
@nevans nevans added the bug Something isn't working label Oct 10, 2026
Base automatically changed from sequence_set/fix-slice-subset-with-invalid-start-index to master October 10, 2026 03:25
@nevans
nevans merged commit 20aa39c into master Oct 10, 2026
34 checks passed
@nevans
nevans deleted the sequence_set/fix-slice-with-zero-length branch October 10, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant