Questions tagged [generic-derivation]

13 questions
31
votes
2 answers

How to decode an ADT with circe without disambiguating objects

Suppose I've got an ADT like this: sealed trait Event case class Foo(i: Int) extends Event case class Bar(s: String) extends Event case class Baz(c: Char) extends Event case class Qux(values: List[String]) extends Event The default generic…
Travis Brown
  • 135,682
  • 12
  • 352
  • 654
10
votes
1 answer

Generic derivation for ADTs in Scala with a custom representation

I'm paraphrasing a question from the circe Gitter channel here. Suppose I've got a Scala sealed trait hierarchy (or ADT) like this: sealed trait Item case class Cake(flavor: String, height: Int) extends Item case class Hat(shape: String, material:…
Travis Brown
  • 135,682
  • 12
  • 352
  • 654
8
votes
1 answer

Decoding JSON values in circe where the key is not known at compile time

Suppose I've been working with some JSON like this: { "id": 123, "name": "aubergine" } By decoding it into a Scala case class like this: case class Item(id: Long, name: String) This works just fine with circe's generic derivation: scala> import…
Travis Brown
  • 135,682
  • 12
  • 352
  • 654
6
votes
1 answer

Encoding ADT case classes with a discriminator, even when typed as the case class

Suppose I have a ADT in Scala: sealed trait Base case class Foo(i: Int) extends Base case class Baz(x: String) extends Base I want to encode values of this type into the JSON that looks like the following: { "Foo": { "i": 10000 }} { "Baz": { "x":…
Travis Brown
  • 135,682
  • 12
  • 352
  • 654
3
votes
1 answer

Blending Magnolia with Circe's trick for automatic derivation

I've got a typeclass and want to provide semi-automatic and automatic derivation to users. I have a working implementation based on Magnolia and it works really well. There's a trait providing definitions for Typeclass[A], combine[A] and…
3
votes
1 answer

Clarification on NN residual layer back-prop derivation

I've looked everywhere and can't find anything that explains the actual derivation of backprop for residual layers. Here's my best attempt and where I'm stuck. It is worth mentioning that the derivation that I'm hoping for is from a generic…
3
votes
2 answers

C# - Call a derived base method in the derived context

Tried to search the web but found nothing so far so here my question: I want to index model-information via attributes on the different members. To do this i created a function in a base class that gathers all needed information when called. This…
Care.Inc
  • 31
  • 3
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,280
  • 1
  • 12
  • 23
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,280
  • 1
  • 12
  • 23
1
vote
1 answer

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
  • 11,442
  • 2
  • 35
  • 62
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…
0
votes
1 answer

C++ Overriding Function with Inner Class Argument

I have an abstract graph (A in the example). And it has inner-class InnerA which is used for one of the functions. I want to derive a new class (e.g. B) from this class and make a wrapper around InnerA to add a new field that should be used in…
0
votes
0 answers

Describing Language Grammar

I have this grammar that I want to describe in english. I understand how to describe most grammar but I have never come across one that uses commas between non-terminals. My guess is that it means "AND" but I am not sure and I need some help. This…
Jeff
  • 165
  • 6