From cf586b319e9adc02ec29cb5cfd80d1c813bdede3 Mon Sep 17 00:00:00 2001 From: Luka Jacobowitz Date: Mon, 5 Feb 2018 10:10:30 +0100 Subject: [PATCH] Hide more newtype machinery --- core/src/main/scala/cats/data/NonEmptyMapImpl.scala | 12 +++++------- .../main/scala/cats/laws/discipline/Arbitrary.scala | 2 +- .../src/test/scala/cats/tests/NonEmptyMapSuite.scala | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/scala/cats/data/NonEmptyMapImpl.scala b/core/src/main/scala/cats/data/NonEmptyMapImpl.scala index 262669571b..345350567a 100644 --- a/core/src/main/scala/cats/data/NonEmptyMapImpl.scala +++ b/core/src/main/scala/cats/data/NonEmptyMapImpl.scala @@ -23,14 +23,14 @@ import cats.{Always, Apply, Eval, Foldable, Functor, Later, NonEmptyTraverse, No import scala.collection.immutable._ -private[data] trait Newtype2 { self => - type Base - trait Tag extends Any - type Type[A, +B] <: Base with Tag +trait Newtype2 { self => + private[data] type Base + private[data] trait Tag extends Any + private[cats] type Type[A, +B] <: Base with Tag } -object NonEmptyMapImpl extends NonEmptyMapInstances with Newtype2 { +private[data] object NonEmptyMapImpl extends NonEmptyMapInstances with Newtype2 { private[cats] def create[K, A](m: SortedMap[K, A]): Type[K, A] = m.asInstanceOf[Type[K, A]] @@ -241,8 +241,6 @@ private[data] sealed class NonEmptyMapOps[K, A](val value: NonEmptyMapImpl.Type[ def show(implicit A: Show[A], K: Show[K]): String = s"NonEmpty${Show[SortedMap[K, A]].show(toSortedMap)}" - override def toString: String = s"NonEmpty${toSortedMap.toString}" - /** * Typesafe equality operator. * diff --git a/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala index 7b96f1e72b..5334e02935 100644 --- a/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala +++ b/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala @@ -80,7 +80,7 @@ object arbitrary extends ArbitraryInstances0 { a <- A.arbitrary } yield NonEmptyMap((k, a), fa)) - implicit def cogenNonEmptyMap[K: Order : Cogen, A: Order : Cogen]: Cogen[NonEmptyMap.Type[K, A]] = + implicit def cogenNonEmptyMap[K: Order : Cogen, A: Order : Cogen]: Cogen[NonEmptyMap[K, A]] = Cogen[SortedMap[K, A]].contramap(_.toSortedMap) implicit def catsLawsArbitraryForEitherT[F[_], A, B](implicit F: Arbitrary[F[Either[A, B]]]): Arbitrary[EitherT[F, A, B]] = diff --git a/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala index aa8843a1ff..e75f980f13 100644 --- a/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala +++ b/tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala @@ -42,7 +42,7 @@ class NonEmptyMapSuite extends CatsSuite { } test("Show is formatted correctly") { - val nonEmptyMap = NonEmptyMapImpl("Key" -> "Test", SortedMap.empty[String, String]) + val nonEmptyMap = NonEmptyMap.one("Key", "Test") nonEmptyMap.show should ===("NonEmptySortedMap(Key -> Test)") } @@ -169,23 +169,23 @@ class NonEmptyMapSuite extends CatsSuite { test("fromMap round trip") { forAll { l: SortedMap[String, Int] => - NonEmptyMapImpl.fromMap(l).map(_.toSortedMap).getOrElse(SortedMap.empty[String, Int]) should ===(l) + NonEmptyMap.fromMap(l).map(_.toSortedMap).getOrElse(SortedMap.empty[String, Int]) should ===(l) } forAll { nem: NonEmptyMap[String, Int] => - NonEmptyMapImpl.fromMap(nem.toSortedMap) should ===(Some(nem)) + NonEmptyMap.fromMap(nem.toSortedMap) should ===(Some(nem)) } } test("fromMapUnsafe/fromMap consistency") { forAll { nem: NonEmptyMap[String, Int] => - NonEmptyMapImpl.fromMap(nem.toSortedMap) should ===(Some(NonEmptyMapImpl.fromMapUnsafe(nem.toSortedMap))) + NonEmptyMap.fromMap(nem.toSortedMap) should ===(Some(NonEmptyMap.fromMapUnsafe(nem.toSortedMap))) } } test("fromMapUnsafe empty map") { val _ = intercept[IllegalArgumentException] { - NonEmptyMapImpl.fromMapUnsafe(SortedMap.empty[String, Int]) + NonEmptyMap.fromMapUnsafe(SortedMap.empty[String, Int]) } }