Newtype coersion with newtype > 0.4.4
See original GitHub issuein newtype 0.4.4 repr becomes a private
https/repo1.maven.org/maven2/io/estatico/newtype_2.13/0.4.4/newtype_2.13-0.4.4-sources.jar!/io/estatico/newtype/Coercible.scala
final class CoercibleIdOps[A](private val repr: A) extends AnyVal {
@inline def coerce[B](implicit ev: Coercible[A, B]): B = repr.asInstanceOf[B]
}
thus
implicit def coercibleEncoder[A: Coercible[B, *], B: Encoder]: Encoder[A] =
Encoder[B].contramap(_.repr.asInstanceOf[B])
pfps-shopping-cart/modules/core/src/main/scala/shop/http/json.scala:46:28: value repr is not a member of type parameter A
[error] Encoder[B].contramap(_.repr.asInstanceOf[B])
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
I want `coerce` to make my newtype problems disappear. It ...
I want `coerce` to make my newtype problems disappear. It stubbornly refuses. Today I was writing some code with newtypes.
Read more >estatico/scala-newtype - Gitter
I am having issue to derive implicit codecs for tapir with new type. Ben Shaw. @benshaw ... But this stops working in 0.4.4...
Read more >Newtype coercion - Type Classes
The 'newtype' keyword allows us to define a new type that has the same runtime representation as another type. This can become more...
Read more >Newtype: Gundam Model Kits / Gunpla / Paint / Tools
We are the premier destination for all your Gunpla and model kit needs. We have the latest Gundam model kits, and we have...
Read more >Value Classes in Scala - Rock the JVM Blog
libraryDependencies += "io.estatico" %% "newtype" % "0.4.4" ... As we know, the Scala community considers type coercion a bad practice ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The approach using
scalaz-deriving
is quite reasonable (more a la Haskell) but unfortunately doesn’t support derivation for typeclasses from projects such ashttp4s
andciris
.Still, we can take advantage of Scala not being Haskell and do it generally whenever we can, even at the expense of using a safe casting technique.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.