Skip to content

Commit

Permalink
Hide more newtype machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Feb 5, 2018
1 parent d3d1635 commit cf586b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 5 additions & 7 deletions core/src/main/scala/cats/data/NonEmptyMapImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/discipline/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]] =
Expand Down
10 changes: 5 additions & 5 deletions tests/src/test/scala/cats/tests/NonEmptyMapSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}

Expand Down Expand Up @@ -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])
}
}

Expand Down

0 comments on commit cf586b3

Please sign in to comment.