Skip to content

Commit

Permalink
Merge pull request #179 from fthomas/topic/equal-show
Browse files Browse the repository at this point in the history
Add scalaz.{Equal, Show} instances
  • Loading branch information
fthomas committed Jun 16, 2016
2 parents 05dc4e8 + 276c2f9 commit 77ac14b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package eu.timepit.refined

import _root_.scalaz.@@
import _root_.scalaz.Equal
import _root_.scalaz.Show
import eu.timepit.refined.api.RefType
import scala.reflect.macros.blackbox

Expand All @@ -23,4 +25,10 @@ package object scalaz {
override def unsafeRewrapM[T: c.WeakTypeTag, A: c.WeakTypeTag, B: c.WeakTypeTag](c: blackbox.Context)(ta: c.Expr[T @@ A]): c.Expr[T @@ B] =
c.universe.reify(ta.splice.asInstanceOf[T @@ B])
}

implicit def refTypeEqual[F[_, _], T: Equal, P](implicit rt: RefType[F]): Equal[F[T, P]] =
Equal.equalBy(rt.unwrap)

implicit def refTypeShow[F[_, _], T, P](implicit rt: RefType[F], s: Show[T]): Show[F[T, P]] =
Show.shows(tp => s.shows(rt.unwrap(tp)))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package eu.timepit.refined.scalaz

import _root_.scalaz.@@
import _root_.scalaz.std.anyVal._
import _root_.scalaz.syntax.equal._
import _root_.scalaz.syntax.show._
import eu.timepit.refined.TestUtils._
import eu.timepit.refined.api.{ RefType, RefTypeSpec }
import eu.timepit.refined.numeric._
Expand All @@ -23,4 +26,17 @@ class RefTypeSpecScalazTag extends RefTypeSpec[@@]("scalaz.@@") {
property("(T @@ P) <!: T") = wellTyped {
illTyped("implicitly[(Int @@ Positive) <:< Int]", "Cannot prove.*")
}

property("scalaz.Equal") = secure {
type PosInt = Int @@ Positive
val x: PosInt = 5
val y: PosInt = 5
x === y
}

property("scalaz.Show") = secure {
type PosInt = Int @@ Positive
val x: PosInt = 5
x.shows ?= "5"
}
}
4 changes: 4 additions & 0 deletions notes/0.5.0.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* Renamed `RefinePartiallyApplied.force` to `unsafeFrom` and add
`ApplyRefPartiallyApplied.unsafeFrom`. ([#175])
* Add `Arbitrary` instance for `Equal`. ([#170])
* Add `scalaz.Equal` and `scalaz.Show` instances for refined types.
These instances use the respective instances of the base types.
([#179])

### Updates

Expand All @@ -32,3 +35,4 @@
[#172]: https://github.com/fthomas/refined/pull/172
[#175]: https://github.com/fthomas/refined/pull/175
[#178]: https://github.com/fthomas/refined/pull/178
[#179]: https://github.com/fthomas/refined/pull/179

0 comments on commit 77ac14b

Please sign in to comment.