Skip to content

Partition a finite collection? #1028

@vreuter

Description

@vreuter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions