Skip to content

Commit d5a7e2f

Browse files
committed
Add the Empty[SortedMap[A, B]] instance in alleycats
1 parent 78d9d55 commit d5a7e2f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

alleycats-core/src/main/scala/alleycats/Empty.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ package alleycats
2424
import cats.{Eq, Monoid}
2525
import cats.syntax.eq.*
2626

27+
import scala.collection.immutable.SortedMap
28+
2729
trait Empty[A] extends Serializable {
2830
def empty: A
2931

@@ -84,6 +86,9 @@ private[alleycats] trait EmptyInstances0 extends compat.IterableEmptyInstance wi
8486

8587
private[this] val emptyMapSingleton: Empty[Map[Nothing, Nothing]] = Empty(Map.empty)
8688
implicit def alleycatsEmptyForMap[A, B]: Empty[Map[A, B]] = emptyMapSingleton.asInstanceOf[Empty[Map[A, B]]]
89+
90+
implicit def alleycatsEmptyForSortedMap[A: Ordering, B]: Empty[SortedMap[A, B]] =
91+
Empty(SortedMap.empty[A, B])
8792
}
8893

8994
private[alleycats] trait EmptyInstances1 extends EmptyInstances2 {

alleycats-core/src/test/scala/alleycats/SyntaxSuite.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ package alleycats
2424
import cats.{Eq, Foldable}
2525
import alleycats.syntax.all.{catsSyntaxExtract, EmptyOps, ExtraFoldableOps}
2626

27+
import scala.collection.immutable.SortedMap
28+
2729
/**
2830
* Test that our syntax implicits are working.
2931
*
@@ -70,6 +72,14 @@ object SyntaxSuite {
7072
val _ = Empty[Map[Foo[Int], Foo[String]]].empty
7173
}
7274

75+
def testSortedMapEmpty(): Any = {
76+
case class Foo[A](foo: A)
77+
78+
implicit def fooOrd[A: Ordering]: Ordering[Foo[A]] = Ordering.by(_.foo)
79+
80+
val _ = Empty[SortedMap[Foo[Int], Foo[String]]].empty
81+
}
82+
7383
def testFoldable[F[_]: Foldable, A](): Unit = {
7484
val x = mock[F[A]]
7585
val y = mock[A => Unit]

0 commit comments

Comments
 (0)