Skip to content

Commit

Permalink
Update shapeless and fix TraverseSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Sep 26, 2021
1 parent 67a012c commit 99429bf
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val catsVersion = "2.6.1"
val disciplineMunitVersion = "1.0.9"
val kindProjectorVersion = "0.13.0"
val shapeless2Version = "2.3.7"
val shapeless3Version = "3.0.2"
val shapeless3Version = "3.0.3"

lazy val commonSettings = Seq(
scalacOptions := Seq(
Expand Down
59 changes: 28 additions & 31 deletions core/src/main/scala-3/cats/derived/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@ package cats.derived

import cats.*

extension (F: Foldable.type)
inline def derived[F[_]]: Foldable[F] = DerivedFoldable[F]

extension (F: Functor.type)
inline def derived[F[_]]: Functor[F] = DerivedFunctor[F]

extension (F: Reducible.type)
inline def derived[F[_]]: Reducible[F] = DerivedReducible[F]

extension (F: Traverse.type)
inline def derived[F[_]]: Traverse[F] = DerivedTraverse[F]

object semiauto extends
CommutativeMonoidDerivation,
CommutativeSemigroupDerivation,
ContravariantDerivation,
EmptyDerivation,
EmptyKDerivation,
EqDerivation,
HashDerivation,
InvariantDerivation,
MonoidDerivation,
MonoidKDerivation,
OrderDerivation,
PartialOrderDerivation,
SemigroupDerivation,
SemigroupKDerivation,
ShowDerivation,
Instances:
import scala.util.NotGiven

extension (F: Foldable.type) inline def derived[F[_]]: Foldable[F] = DerivedFoldable[F]

extension (F: Functor.type) inline def derived[F[_]]: Functor[F] = DerivedFunctor[F]

extension (F: Reducible.type) inline def derived[F[_]]: Reducible[F] = DerivedReducible[F]

extension (F: Traverse.type) inline def derived[F[_]]: Traverse[F] = DerivedTraverse[F]

object semiauto
extends CommutativeMonoidDerivation,
CommutativeSemigroupDerivation,
ContravariantDerivation,
EmptyDerivation,
EmptyKDerivation,
EqDerivation,
HashDerivation,
InvariantDerivation,
MonoidDerivation,
MonoidKDerivation,
OrderDerivation,
PartialOrderDerivation,
SemigroupDerivation,
SemigroupKDerivation,
ShowDerivation,
Instances:

inline def foldable[F[_]]: Foldable[F] = DerivedFoldable[F]

Expand All @@ -40,7 +38,6 @@ object semiauto extends

inline def traverse[F[_]]: Traverse[F] = DerivedTraverse[F]


object auto:
object functor:
inline given [F[_]]: Functor[F] = DerivedFunctor[F]
Expand All @@ -52,4 +49,4 @@ object auto:
inline given [F[_]]: Reducible[F] = DerivedReducible[F]

object traverse:
inline given [F[_]]: Traverse[F] = DerivedTraverse[F]
inline given [F[_]](using NotGiven[Traverse[F]]): Traverse[F] = DerivedTraverse[F]
81 changes: 43 additions & 38 deletions core/src/test/scala-3/cats/derived/TraverseSuite.scala
Original file line number Diff line number Diff line change
@@ -1,65 +1,70 @@
package cats
package derived
package cats.derived

import cats.{Eq, Traverse}
import cats.laws.discipline.{SerializableTests, TraverseTests}
import org.scalacheck.Arbitrary

class TraverseSuite extends KittensSuite {
import scala.compiletime.*

class TraverseSuite extends KittensSuite:
import TestDefns.*
import TraverseSuite.*

def testTraverse(context: String)(implicit
iList: Traverse[IList],
tree: Traverse[Tree],
genericAdt: Traverse[GenericAdt],
optList: Traverse[OptList],
listSnoc: Traverse[ListSnoc],
andChar: Traverse[AndChar],
interleaved: Traverse[Interleaved]
): Unit = {
checkAll(s"$context.Traverse[IList]", TraverseTests[IList].traverse[Int, Double, String, Long, Option, Option])
checkAll(s"$context.Traverse[Tree]", TraverseTests[Tree].traverse[Int, Double, String, Long, Option, Option])
inline def traverseTests[F[_]]: TraverseTests[F] =
TraverseTests[F](summonInline)

inline def testTraverse(inline context: String): Unit =
checkAll(s"$context.Traverse[IList]", traverseTests[IList].traverse[Int, Double, String, Long, Option, Option])
checkAll(s"$context.Traverse[Tree]", traverseTests[Tree].traverse[Int, Double, String, Long, Option, Option])
checkAll(
s"$context.Traverse[GenericAdt]",
TraverseTests[GenericAdt].traverse[Int, Double, String, Long, Option, Option]
traverseTests[GenericAdt].traverse[Int, Double, String, Long, Option, Option]
)
checkAll(s"$context.Traverse[OptList]", TraverseTests[OptList].traverse[Int, Double, String, Long, Option, Option])
checkAll(s"$context.Traverse[OptList]", traverseTests[OptList].traverse[Int, Double, String, Long, Option, Option])
checkAll(
s"$context.Traverse[ListSnoc]",
TraverseTests[ListSnoc].traverse[Int, Double, String, Long, Option, Option]
traverseTests[ListSnoc].traverse[Int, Double, String, Long, Option, Option]
)
checkAll(s"$context.Traverse[AndChar]", TraverseTests[AndChar].traverse[Int, Double, String, Long, Option, Option])
checkAll(s"$context.Traverse[AndChar]", traverseTests[AndChar].traverse[Int, Double, String, Long, Option, Option])
checkAll(
s"$context.Traverse[Interleaved]",
TraverseTests[Interleaved].traverse[Int, Double, String, Long, Option, Option]
traverseTests[Interleaved].traverse[Int, Double, String, Long, Option, Option]
)
checkAll(s"$context.Traverse is Serializable", SerializableTests.serializable(Traverse[Tree]))
}
checkAll(s"$context.Traverse is Serializable", SerializableTests.serializable(summonInline[Traverse[Tree]]))

{
locally {
import auto.traverse.given
testTraverse("auto")
}

{
import semiInstances._
locally {
import semiInstances.given
testTraverse("semiauto")
}
}

object TraverseSuite {
import TestDefns._
end TraverseSuite

object TraverseSuite:
import TestDefns.*

type OptList[A] = Option[List[A]]
type ListSnoc[A] = List[Snoc[A]]
type AndChar[A] = (A, Char)

object semiInstances {
implicit val iList: Traverse[IList] = semiauto.traverse
implicit val tree: Traverse[Tree] = semiauto.traverse
implicit val genericAdt: Traverse[GenericAdt] = semiauto.traverse
implicit val optList: Traverse[OptList] = semiauto.traverse
implicit val listSnoc: Traverse[ListSnoc] = semiauto.traverse
implicit val andChar: Traverse[AndChar] = semiauto.traverse
implicit val interleaved: Traverse[Interleaved] = semiauto.traverse
}
}
// FIXME: Doesn't work if we define `ListAndNel` as a type alias
case class AndChar[A](value: A, letter: Char)
object AndChar:
given [A: Eq]: Eq[AndChar[A]] =
Eq.by(ac => (ac.value, ac.letter))
given [A: Arbitrary]: Arbitrary[AndChar[A]] =
Arbitrary(Arbitrary.arbitrary[(A, Char)].map(apply[A].tupled))

object semiInstances:
given Traverse[IList] = semiauto.traverse
given Traverse[Tree] = semiauto.traverse
given Traverse[GenericAdt] = semiauto.traverse
given Traverse[OptList] = semiauto.traverse
given Traverse[ListSnoc] = semiauto.traverse
given Traverse[AndChar] = semiauto.traverse
given Traverse[Interleaved] = semiauto.traverse

end TraverseSuite

0 comments on commit 99429bf

Please sign in to comment.