-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from tofu-tf/newtypes
Support estatico newtypes
- Loading branch information
Showing
22 changed files
with
147 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ target/ | |
.metals | ||
.bloop | ||
.vscode | ||
metals.sbt | ||
metals.sbt | ||
.bsp | ||
.metals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
moduleName := "derevo-circe" | ||
|
||
libraryDependencies += "io.circe" %% "circe-core" % Version.circe | ||
libraryDependencies += "io.circe" %% "circe-derivation" % Version.circeDerivation | ||
libraryDependencies += "io.circe" %% "circe-parser" % Version.circe % "test" | ||
libraryDependencies += "org.scalatest" %% "scalatest" % Version.scalaTest % "test" | ||
libraryDependencies += "io.circe" %% "circe-core" % Version.circe | ||
libraryDependencies += "io.circe" %% "circe-derivation" % Version.circeDerivation | ||
libraryDependencies += "io.circe" %% "circe-parser" % Version.circe % "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package derevo | ||
|
||
/** Utilitary holder for the newtype instance derivation */ | ||
class NewTypeRepr[TC[_], R](private val repr: TC[R]) extends AnyVal { | ||
def instance[A]: TC[A] = repr.asInstanceOf[TC[A]] | ||
} | ||
|
||
trait NewTypeDerivation[TC[_]] { | ||
final def newtype[R](implicit repr: TC[R]): NewTypeRepr[TC, R] = new NewTypeRepr[TC, R](repr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package derevo | ||
|
||
import io.estatico.newtype.macros.newtype | ||
import scala.language.implicitConversions | ||
import scala.reflect.{ClassTag, classTag} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
|
||
class Kyon[A](val cls: Any) | ||
|
||
object Kyon extends Derivation[Kyon] { | ||
def instance[A](implicit cls: ClassTag[A]): Kyon[A] = new Kyon(cls) | ||
def newtype[Repr]: Newtype[Repr] = new Newtype[Repr] | ||
|
||
class Newtype[Repr] { | ||
def instance[A](implicit cls: ClassTag[Repr]): Kyon[A] = new Kyon(cls) | ||
} | ||
} | ||
|
||
class KyonSuite extends AnyFlatSpec { | ||
import KyonSuite._ | ||
|
||
"newtype derivation" should "implicitly receive classtag" in { | ||
assert(implicitly[Kyon[Datus[Unit]]].cls === classTag[String]) | ||
} | ||
} | ||
|
||
object KyonSuite { | ||
@derive(Kyon) | ||
@newtype | ||
case class Datus[@phantom A](x: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.