typelevel / typelevel/cats

Add Seq syntax parallel to ListOps

Open
#4,404 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing ListOps helpers and the Seq and NonEmptySeq APIs, then compare the requested scope with issue #4070. The work is done when Seq has equivalent grouping and emptiness-related helpers for producing NonEmptySeq values, with tests covering the stated Seq[Value] grouping use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.