scala-newtype icon indicating copy to clipboard operation
scala-newtype copied to clipboard

recursive coerce

Open valenterry opened this issue 6 years ago • 1 comments

I often wrap newtypes in newtypes and then I want to access the basetype. Example:

@newtype case class Secret(value: String)
@newtype case class Password(value: Secret)
@newtype case class AdminPassword(value: Password)

val adminPassword: AdminPassword = ???

// Access the basetype
println(adminPassword.value.value.value)

Something like adminPassword.coerce[String] would be nice, or maybe even adminPassword.underlying. As Coercible is a typeclass, I think with the correct derivation it should be possible to get something like it.

Opinions?

valenterry avatar Oct 27 '19 04:10 valenterry

+1 to this. I found myself in the same situation and I think it's doable.

gvolpe avatar Dec 03 '19 01:12 gvolpe