Skip to content

fix: improve typing for intersect(), union() and substract()#20

Merged
delacry merged 1 commit into
noctud:0.1.xfrom
nikophil:narrow-set-operations-generics
Jul 25, 2026
Merged

fix: improve typing for intersect(), union() and substract()#20
delacry merged 1 commit into
noctud:0.1.xfrom
nikophil:narrow-set-operations-generics

Conversation

@nikophil

@nikophil nikophil commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

here are some typing improvements:

  • Intersects should narrow the types:
$intsAndStrings = listOf(['a', 1]); // List<int|string>
$onlyInts = $intsAndStrings->intersect(listOf([1])); // List<int>
  • union should widden the types: (actually, I'm wondering if you'll be OK with this one 😅)
$ints = listOf([1, 2]);
$intsAndStrings = $ints->union(listOf(['a']));
  • substract should allow anything

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@delacry delacry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

union should widden the types: (actually, I'm wondering if you'll be OK with this one 😅)

Yeah that's okay, type widening is fine as it doesn't widen existing collection, but creates a new one.

Comment thread tests/Type/SetOperationsTypeTest.php
@delacry
delacry merged commit 0946615 into noctud:0.1.x Jul 25, 2026
6 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.

2 participants