fix: narrow filterNotNull() and filterValuesNotNull() return types#18
Conversation
Use a conditional return type so that filtering out nulls also removes null from the element type: ImmutableList<int|null>::filterNotNull() is now typed ImmutableList<int>, and Map<K, V|null>::filterValuesNotNull() is now typed Map<K, V>. Fixes noctud#16
Codecov Reportβ All modified and coverable lines are covered by tests. π’ Thoughts on this report? Let us know! |
|
Thank you very much! I was just thinking about it, because I said I'll look at it yesterday (but I haven't found the time), this looks perfect, I'll merge it and tag the next version right away. |
|
@delacry LOL while rebasing #19, I asked Claude to spread tests in
so.... congrats ? π BTW, there's a feature request for being able to substract types in PHPStan phpstan/phpstan#3182 |
Yeeah.. so I'm going to pass that congrats to my Fable 5 with max effort π I told it to have crack at it, I just suspected that it might be possible. It's interesting how the AI is progressing, because when I started to write the library in the summer of 2025, it was no where near the level as it is now, I described whole library in detail in one big MD file and I hoped AI would do most of the work, but when I saw the result I just deleted it right away and wrote it by hand from scratch, and only like 4 months after there were solid foundation I started using AI for some verifications, fixing docblocks and adding some methods that I missed, and writing some tests I wouldn't otherwise wrote. And I remember solving this |
|
yeah I also feel like 2026 is the game changing year with AI I'm pretty sure you'd give your .md now to Fable 5, the result would be much more acceptable |
Update the API reference for narrowing that landed in #15, #17, #18, #19, #21 and #22: flatten(), filterNotNull(), Map::filterValuesNotNull(), countWhere(), Collection::sum() and Map::toArray(). Compact types are inlined in the signature (countWhere(): int<0, max>); conditional ones are described in prose instead, matching how sum() and intersect() are already documented. Also fix the flatten() assertion in TransformTypeTest, which still expected Collection<mixed> and has failed on 0.1.x since #21.
Hi! I just gave a try to the solution you suggested to remove
nullfrom the typefixes #16