From 14cb6a4631a88e9b36a5c102a2a95a8fe55880e0 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 30 Oct 2024 00:18:11 +0100 Subject: [PATCH] add .groupBy operations --- modules/pan/src/main/scala/collections.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/pan/src/main/scala/collections.scala b/modules/pan/src/main/scala/collections.scala index 7a8b737..7f33f72 100644 --- a/modules/pan/src/main/scala/collections.scala +++ b/modules/pan/src/main/scala/collections.scala @@ -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) @@ -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