From 57e907c64da01a0285c032185453a8c36af3a8d2 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 | 10 +++++----- .../main/scala/cats/laws/discipline/Arbitrary.scala | 2 +- tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/scala/cats/data/NonEmptyMapImpl.scala b/core/src/main/scala/cats/data/NonEmptyMapImpl.scala index 262669571b9..1edf78aec67 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]] diff --git a/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala b/laws/src/main/scala/cats/laws/discipline/Arbitrary.scala index 7b96f1e72be..5334e029352 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 aa8843a1ff2..e75f980f13d 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]) } }