Skip to content

Commit

Permalink
Merge pull request #160 from dwijnand/non-case-class
Browse files Browse the repository at this point in the history
Drop case in Refined
  • Loading branch information
fthomas committed May 7, 2016
2 parents 4b13ab0 + bdd1898 commit 55fb5c0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
10 changes: 9 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ lazy val submoduleJvmSettings = Seq(
Seq(
exclude[DirectMissingMethodProblem ]("eu.timepit.refined.generic.evalValidate"),
exclude[DirectMissingMethodProblem ]("eu.timepit.refined.GenericValidate.evalValidate"),
exclude[ReversedMissingMethodProblem]("eu.timepit.refined.GenericValidate.evalValidate")
exclude[ReversedMissingMethodProblem]("eu.timepit.refined.GenericValidate.evalValidate"),
exclude[MissingTypesProblem]("eu.timepit.refined.api.Refined"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productElement"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productArity"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.canEqual"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.copy"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productIterator"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productPrefix"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.apply")
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ package api
* this class can be created with `[[refineV]]` and `[[refineMV]]` which
* verify that the wrapped value satisfies `P`.
*/
final case class Refined[T, P] private (get: T) {
final class Refined[T, P] private (val get: T) extends Serializable {
override def hashCode: Int = get.##
override def equals(that: Any): Boolean = that match {
case that: Refined[_, _] => this.get == that.get
case _ => false
}

override def toString: String =
get.toString
Expand All @@ -20,6 +25,10 @@ object Refined {
*/
def unsafeApply[T, P](t: T): Refined[T, P] =
new Refined(t)

def unapply[T, P](r: Refined[T, P]): Option[T] =
Some(r.get)

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package api
* this class can be created with `[[refineV]]` and `[[refineMV]]` which
* verify that the wrapped value satisfies `P`.
*/
final case class Refined[T, P] private (get: T) extends AnyVal {
final class Refined[T, P] private (val get: T) extends AnyVal with Serializable {

override def toString: String =
get.toString
Expand All @@ -20,4 +20,8 @@ object Refined {
*/
def unsafeApply[T, P](t: T): Refined[T, P] =
new Refined(t)

def unapply[T, P](r: Refined[T, P]): Option[T] =
Some(r.get)

}
26 changes: 26 additions & 0 deletions core/shared/src/test/scala/eu/timepit/refined/RefinedSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.timepit.refined

import eu.timepit.refined.TestUtils.wellTyped
import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.NonEmpty
import org.scalacheck.Properties
import shapeless.test.illTyped

class RefinedSpec extends Properties("Refined") {
type NonEmptyString = String Refined NonEmpty

property("apply") = wellTyped {
illTyped(
""" val x: NonEmptyString = Refined("") """,
"eu.timepit.refined.api.Refined.type does not take parameters"
)
}

property("copy") = wellTyped {
val nonEmptyString1: NonEmptyString = refineMV[NonEmpty]("abc")
illTyped(
""" nonEmptyString1.copy("") """,
"value copy is not a member of RefinedSpec\\.this\\.NonEmptyString"
)
}
}

0 comments on commit 55fb5c0

Please sign in to comment.