question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newtype coersion with newtype > 0.4.4

See original GitHub issue

in 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:closed
  • Created 3 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gvolpecommented, Jun 2, 2020

The approach using scalaz-deriving is quite reasonable (more a la Haskell) but unfortunately doesn’t support derivation for typeclasses from projects such as http4s and ciris.

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.

0reactions
stale[bot]commented, Aug 1, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found