Skip to content

Add groupByTo and groupMapTo to IterableOnceOps #51

Open
@BalmungSan

Description

@BalmungSan

Similar to #8 the only reason why Iterators (or IterableOnce in general) do not have groupBy & groupMap is because, you can not have a Map[K, Iterator[V]] without consuming the Iterator as such the values of the Map would be empty.

But, since groupBy & groupMap already consume the Iterator I would say nobody would expect the values to be a lazy collection, I would even say that most people would be ok with either List or Seq.
However, I would guess that the best would be just giving users the possibility to choose which collection to use to collect the results; this even opens the possibility to a somewhat common requirement of grouping unique values by using a Set.

So the proposal is to add the following two methods to IterableOnceOps so they are not only available on Iterator but for all collections.

def groupByTo[C, K](factory: Factory[A, C])(key: A => K): Map[K, C]
def groupMapTo[C, K, B](factory: Factory[B, C])(key: A => K)(f: A => B): Map[K, C]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlibrary:collectionsstatus:pendingThis enhancement request lacks consensus on whether or not to include it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions