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

Add Seq syntax parallel to ListOps #4404

Open
nigredo-tori opened this issue Feb 28, 2023 · 0 comments
Open

Add Seq syntax parallel to ListOps #4404

nigredo-tori opened this issue Feb 28, 2023 · 0 comments

Comments

@nigredo-tori
Copy link
Contributor

nigredo-tori commented Feb 28, 2023

In ListOps we have a few helper methods for producing NonEmptyLists via grouping, emptiness check, etc.. We can do the same thing with Seq and NonEmptySeq.

My specific use case (which I have hit a few times by this point) is that I have a Seq[Value], and I want to group it into a Map[Key, NonEmptySeq[Value]]. At the moment there are two ways to do this:

val values: Seq[Value] = ???
def f(v: Value): Key = ???
// This switches to `List`s which can be inefficient. Also, this is noisy, and it has an "unsafe" call.
values.toList.groupByNel(f).mapValues(nel => NonEmptySeq.fromSeqUnsafe(nel.toList))
// This is still noisy
NonEmptySeq.fromSeq(values).map(_.groupByNem(f).toMap)(Map.empty)

This might be a subset of #4070, but that one is huge and stale. I'd rather have a separate issue for this specific pain point.

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