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.

Scala ADT encoding improvements

See original GitHub issue

For best practice with Scala ADTS:

  • All case class definitions should be marked as final to avoid subclassing
  • ADT trait should be marked extends Product with Serializable The reason for this is that the calculated LUB for the subtypes is not just the trait, due to the extra code mixed in by case class or case object. We want the inferred type to be just the trait, this especially helps when using code which has invariant type parameters.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mbryzekcommented, May 22, 2020

case classes are final - closing issue

1reaction
fiadlielcommented, Apr 23, 2018

Making case classes final is best practice, for many reasons.

Some people discuss this issue at https://stackoverflow.com/questions/37184528/mock-case-class-in-scala-mockito

In general, these case classes model data. Data doesn’t need to be mocked, it just is (you can create a value at any time). You probably want to be looking at the interfaces that return data, and perhaps mocking them instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circe | ADT (Algebraic Data Types) - Scala Exercises
The most straightforward way to encode / decode ADTs is by using generic derivation for the case classes but explicitly defined instances for...
Read more >
Proposal for Enumerations in Scala
Scala Improvement Process ... Today, enumerations are usually encoded via one of two mechanisms: Simply making use of Java enumerations (rarely).
Read more >
Encoding ADT case classes with a discriminator, even when ...
Suppose I have a ADT in Scala: sealed trait Base case class Foo(i: Int) extends Base case class Baz(x: String) extends Base.
Read more >
ADT (Algebraic Data Types) - circe
The most straightforward way to encode / decode ADTs is by using generic derivation for the case classes but explicitly defined instances for...
Read more >
Generic derivation: the hard parts - Travis Brown
... and sealed traits) * Type classes (and their encoding in Scala) * Shapeless's ... recursive ADT: ```scala import io.circe.examples.derivation.simple.
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