Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partition a finite collection? #1028

Open
vreuter opened this issue Jan 4, 2024 · 0 comments
Open

Partition a finite collection? #1028

vreuter opened this issue Jan 4, 2024 · 0 comments

Comments

@vreuter
Copy link

vreuter commented Jan 4, 2024

I don't see anything in the API to support partitioning a finite collection. Did I miss something? If not, would there be interest in having such a generation strategy? Something along the lines of...

object Gen:
    ...
    def partition[A](n: Int, elems: Set[A]): List[Set[A]]
object Gen

then satisfying
a) nonoverlapping: sub1 & sub2 === Set.empty[A] for all (sub1, sub2) in the result, and
b) covering: result.foldLeft(Set.empty[A])(_ |+| _) === elems

While this could be made strict w.r.t. input size (e.g., require(n <= elems.size), since the element type in the output collection would be Set rather than a nonempty set, I think it would make sense to allow empty elements in the output collection if this would be implemented.

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

No branches or pull requests

1 participant