Skip to content

Commit

Permalink
add .groupBy operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Oct 29, 2024
1 parent cae5099 commit 14cb6a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/pan/src/main/scala/collections.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ object collections:
*/
def contains(x: X): Boolean = (xs: Set[X]).contains(x)

/** Use the underlying collection's {@code .groupBy} operation */
def groupBy[K](f: X => K): Map[K, Set[X]] = (xs: Set[X]).groupBy(f)

/** Convert safely to [[cats.data.NonEmptySet]]. */
def toNes(using ord: Order[X]): NonEmptySet[X] =
NonEmptySet.fromSetUnsafe(xs.toSortedSet)
Expand All @@ -120,6 +123,9 @@ object collections:
*/
def contains(x: X): Boolean = (xs: List[X]).contains(x)

/** Use the underlying collection's {@code .groupBy} operation */
def groupBy[K](f: X => K): Map[K, List[X]] = (xs: List[X]).groupBy(f)

/** Access the first element of the collection. */
def head: X = (xs: List[X]).head

Expand Down

0 comments on commit 14cb6a4

Please sign in to comment.