Skip to content

Conversation

@kyay10
Copy link
Collaborator

@kyay10 kyay10 commented Dec 29, 2025

The builders work by giving the caller a MonotoneMutableList/Set and forcing the caller to return a NonEmpty & List/Set. Operations on MonotoneMutableList/Set that are sure to add items, like add and addAll(NonEmptyCollection), have a contract that gives their receiver the apt intersection type.

This PR also removes most usages of NonEmptyList/Set(), as in the unsafe constructors, and most usages of PotentiallyUnsafeNonEmptyOperation. This also meant that a lot of warning suppressions for WRONG_INVOCATION_KIND and LEAKED_IN_PLACE_LAMBDA were finally removed!

The PR doesn't compromise on inline bytecode size, either. In particular, it would be easy to call inline lambdas multiple times to get AT_LEAST_ONCE to comply. Instead, I've extensively used do-while, which resulted in cleaner code, anyway.

@kyay10 kyay10 requested a review from serras December 29, 2025 23:00
@kyay10 kyay10 changed the title kyay10/non-empty-mutable-collections NonEmptyCollection builders Dec 29, 2025
@kyay10
Copy link
Collaborator Author

kyay10 commented Dec 30, 2025

Note to self: There seems to be a strange compilation mishap with NonEmptySet and default methods. I'll work around it for now

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