Questions tagged [generic-derivation]
33 questions
2
votes
2 answers
Shapeless: what the difference between these two approaches of instance derivation?
Can someone explain me what the difference between these two approaches for typeclass instance derivation (specifically for Option[A])?
1.
trait MyTrait[A] {...}
object MyTrait extends LowPriority {
// instances for primitives
}
trait LowPriority…

Nikita Ryanov
- 1,520
- 3
- 17
- 34
2
votes
0 answers
How to access default values for case class fields?
I want to derive instances of some type (Decoder[A]) for arbitrary case classes using shapeless.
trait Decoder[A] extends Serializable { self =>
def decode(source: String): Either[Throwable, A]
}
If i don't consider the default values for case…

Nikita Ryanov
- 1,520
- 3
- 17
- 34
1
vote
1 answer
How to access method valueOf of an unknown enum in Scala 3
I'm trying to create inline def to generate Json codec for any enums in Scala 3. For this I need to have access to valueOf method of the parent of the enum. Something like this:
inline def gen[T](using JsonCodec[String], T <:< reflect.Enum):…

sergeda
- 2,061
- 3
- 20
- 43
1
vote
1 answer
Shapeless - How to derive LabelledGeneric for Coproduct
I'm trying to generate LabelledGeneric for Coproduct, so that it can be used instead of typical sealed trait hierarchy. So far I was able to do it by explicit specification of labels for DefaultSymbolicLabelling, but I feel it should be possible to…

user3663733
- 23
- 5
1
vote
1 answer
How to derive a Generic.Aux if the case class has a type parameter - Shapeless
given:
sealed trait Data
final case class Foo() extends Data
final case class Bar() extends Data
final case class TimestampedData[A <: Data](data: A, timestamp: Long)
Is there a succint way to generate, for example, a Generic.Aux that will take…

eitaporra
- 51
- 7
1
vote
1 answer
How to Decode a Generic Case Class with semiautomatic in Circe in Scala 3
The following code works with Scala 2.13 (see https://stackoverflow.com/a/59996748/2750966):
import io.circe.generic.semiauto._
case class Name(name: String)
case class QueryResult[T: Decoder](data: T)
implicit val nameDer =…

pme
- 14,156
- 3
- 52
- 95
1
vote
1 answer
Scala typeclass for providing an instance either from derivation or from an existing implicit value
I'm getting started with generic programming in Scala and I'm trying to design a flexible buildable schema type (a generic description of ADTs) that can be translated into third party serialization (e.g., circe, upickle) or schema (e.g., tapir) type…

John Hungerford
- 95
- 7
1
vote
0 answers
Cannot Serialise a Map with Sealed Trait as Key Type
I cannot seem to specify the formatting for this type:
sealed trait Baz
object Baz {
case object A extends Baz
implicit val format: OFormat[Baz] = derived.oformat[Baz]()
}
final case class Foo(s: Map[Baz, String])
object Foo {
implicit val…

Mojo
- 1,152
- 1
- 8
- 16
1
vote
1 answer
Printing MirroredElemTypes in Scala 3
I am trying to modify this standard example to print values with the types.
And I am stuck with p.MirroredElemTypes. I haven't found any API to traverse and stringify types.

St.
- 521
- 3
- 8
1
vote
1 answer
Scala3 macro summon typeclass instance of a TypeTree (no type arg)
trait Show[T] {
def show(t: T): String
}
Give such Show typeclass, I want to generate show for case class like
def caseClassShow[A](using Type[A], Quotes): Expr[Show[A]] = {
import quotes.reflect._
def shows(caseClassExpr: Expr[A]):…

jilen
- 5,633
- 3
- 35
- 84
1
vote
2 answers
How to Decode a Generic Case Class with semiautomatic in Circe
I have the following case class:
case class QueryResult[T: Decoder](data: T)
It works with auto derivation.
But I could not solve it to have a semiautomatic derivation.
Here is my Test case:
//import io.circe.generic.auto._ // with this it works
…

pme
- 14,156
- 3
- 52
- 95
1
vote
1 answer
Is that possible to make semiauto decoders consider default values for case class fields?
Is that possible to make semiauto decoders consider default values for case class fields?
The following code will fail with:
Left(DecodingFailure(Attempt to decode value on failed cursor, List(DownField(isActive))))
I thought circe would consider…

Geovanny Junio
- 68
- 4
0
votes
0 answers
zio-json with io.estatico.newtype.macros.newtype
zio-json is unable to derive an encoder (using DeriveJsonEncoder.gen) for a case class with the @newtype annotation.
I'd rather not write even simple custom encoders for the hundreds of such classes we have. Is there any way, perhaps with some…

Bender Rodriguez
- 67
- 6
0
votes
2 answers
Scala how to derivate a type class on a trait
In the following example I would like to be capable to use an implicit type class - Process - wit a trait as input. But the compilator does not recognize any implicit in that case. I was expecting as Input is a sealed trait and I made the implicits…

gwenael
- 35
- 5
0
votes
1 answer
Parsing Tree and Derivation?
I don't understand the relantioship between parsing tree and derivation. The parsing tree is invariant with respect to the derivation, but does this mean that regardless of the derivation (rightmost or leftmost) the parsing tree remains the same? Or…

xXMarcoXx
- 11
- 4