-
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
So generally it's not possible to abstract over 'raw' opaque types (or maybe it is, extensions do show up in the symbol list when reflected over 🤔) but that is easily addressable if you sprinkle some trait Newtype[A] {
opaque type Type = A
def apply(value: A): Type = value
def wrapAll[F[_]](unwrapped: F[A]): F[Type] = unwrapped
def unwrapAll[F[_]](wrapped: F[Type]): F[A] = wrapped
extension (self: Type) {
def value: A = self
}
given wrappingTransformer: Transformer[A, Type] = apply
given uwnrappingTransformer: Transformer[Type, A] = _.value
} Given the above your example would look like this (impl taken from here): object TypeName extends Newtype[String]
export TypeName.Type as TypeName and all of the You could also take a look at a But yeah as I said abstracting over raw opaque types is still an open question (I haven't seen a library that does it, it'd have to be by some kind of arbitrary convention eg. when you find a single arg apply method on the companion you use it for wrapping and if a Hope I answered your question ❤️ |
Beta Was this translation helpful? Give feedback.
-
arainko, thanks for such a detail response! And also thanks for the library, it's very useful. |
Beta Was this translation helpful? Give feedback.
-
Seems like this approach doesn't work for enums: |
Beta Was this translation helpful? Give feedback.
-
What's the expected semantic here? To generate a Oh actually after taking another look at it can you try this instead: enum TeamStatus:
case Enabled, Disabled
object TeamStatus extends Newtype[String](...) Although I don't think newtypes are a good fit for this particular use case since what you're after in this case is an isomorphism between your enum and a String (or a refinement), a newtype isn't really that |
Beta Was this translation helpful? Give feedback.
-
Yes. The only way I find it possible to do is by encapsulating enum in object, making something like this:
|
Beta Was this translation helpful? Give feedback.
-
@arainko hey, just another small question, is it possible to do a transformation when Destination is trait? I want to pass parameter type to the method but the compiler tells me that my generic parameter is not Product type
And trait is represented as seen below:
|
Beta Was this translation helpful? Give feedback.
So,
P
is a type parameter (not a concrete type) the library is not able to get its strucuture (fields, types etc.)