Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show and Eq instances for cats #284

Merged
merged 3 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions build.sbt
Expand Up @@ -9,6 +9,7 @@ val gitHubOwner = "fthomas"
val gitPubUrl = s"https://github.com/$gitHubOwner/$projectName.git"
val gitDevUrl = s"git@github.com:$gitHubOwner/$projectName.git"

val catsVersion = "0.9.0"
val macroCompatVersion = "1.1.1"
val macroParadiseVersion = "2.1.0"
val shapelessVersion = "2.3.2"
Expand All @@ -23,7 +24,7 @@ val macroParadise = compilerPlugin(
"org.scalamacros" % "paradise" % macroParadiseVersion % Test cross CrossVersion.patch)

val allSubprojects =
Seq("core", "eval", "scalacheck", "scalaz", "scodec", "pureconfig")
Seq("cats", "core", "eval", "scalacheck", "scalaz", "scodec", "pureconfig")
val allSubprojectsJVM = allSubprojects.map(_ + "JVM")
val allSubprojectsJS = {
val jvmOnlySubprojects = Seq("pureconfig")
Expand All @@ -34,7 +35,9 @@ val allSubprojectsJS = {

lazy val root = project
.in(file("."))
.aggregate(coreJVM,
.aggregate(catsJVM,
catsJS,
coreJVM,
coreJS,
docs,
evalJVM,
Expand All @@ -55,6 +58,19 @@ lazy val root = project
parallelExecution in Test in ThisBuild := false
)

lazy val cats = crossProject
.configureCross(moduleCrossConfig("cats"))
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion,
initialCommands += s"""
import $rootPkg.cats._
"""
)

lazy val catsJVM = cats.jvm
lazy val catsJS = cats.js

lazy val core = crossProject
.configureCross(moduleCrossConfig("core"))
.enablePlugins(BuildInfoPlugin)
Expand Down
1 change: 1 addition & 0 deletions latestVersion.sbt
Expand Up @@ -5,4 +5,5 @@ latestVersionInSeries in ThisBuild := Some("0.8.1")
unreleasedModules in ThisBuild := Set(
// Example:
// "refined-eval"
"refined-cats"
)
@@ -0,0 +1,23 @@
package eu.timepit.refined

import _root_.cats.kernel.Eq
import _root_.cats.Show
import _root_.cats.syntax.contravariant._
import eu.timepit.refined.api.RefType

package object cats {

/**
* `Eq` instance for refined types that delegates to the `Eq`
* instance of the base type.
*/
implicit def refTypeEq[F[_, _], T: Eq, P](implicit rt: RefType[F]): Eq[F[T, P]] =
Eq[T].contramap(rt.unwrap)

/**
* `Show` instance for refined types that delegates to the `Show`
* instance of the base type.
*/
implicit def refTypeShow[F[_, _], T: Show, P](implicit rt: RefType[F]): Show[F[T, P]] =
Show[T].contramap(rt.unwrap)
}
@@ -0,0 +1,23 @@
package eu.timepit.refined.cats

import cats.instances.int._
import cats.syntax.eq._
import cats.syntax.show._
import eu.timepit.refined.auto._
import eu.timepit.refined.types.numeric.PosInt
import org.scalacheck.Prop._
import org.scalacheck.Properties

class CatsSpec extends Properties("cats") {

property("Equal") = secure {
val x: PosInt = 5
val y: PosInt = 5
x === y
}

property("Show") = secure {
val x: PosInt = 5
x.show ?= "5"
}
}