All Questions

Tagged with
Filter by
Sorted by
Tagged with
12 votes
2 answers
1k views

Scala extractors - skip unused parameters

given following code: abstract class MyTuple ... case class MySeptet(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int) extends MyTuple case class MyOctet(a: Int, b: Int, c: Int, d: Int, e: ...
vucalur's user avatar
  • 6,057
9 votes
3 answers
8k views

Replacing case class inheritance with extractors preserving exhaustiveness checks in Scala

I have a simple class hierarchy that represents a graph-like structure with several distinct types of vertexes implemented using case classes: sealed trait Node sealed abstract case class Vertex ...
Ivan Poliakov's user avatar
6 votes
3 answers
2k views

Modeling with Scala case class

I'm attempting to model responses from REST APIs as case classes which I can use pattern matching on. I thought it would be a good fit assuming inheritance, but I see that this is deprecated. I know ...
7zark7's user avatar
  • 10k
6 votes
1 answer
557 views

Difference between home made extractor and case class extractor

According to the scala specification, the extractor built by case classes is the following (scala specification §5.3.2): def unapply[tps](x: c[tps]) = if (x eq null) scala.None else scala.Some(x....
Nicolas's user avatar
  • 24.7k
4 votes
1 answer
2k views

How do I write a scala extractor for a case class with default parameters?

I have the following case class with a default parameter and I'm wondering how I can write an unapply method so that I can just extract the first two parameters. I hope the code below is clear. case ...
Jeff Wu's user avatar
  • 2,488
3 votes
1 answer
144 views

Why and how to migrate case class to extractor in Scala

In the Programming in Scala discussion on when to use case classes and when extractors, they say Extractors break [the] link between data representations and patterns ... This property is called ...
joel's user avatar
  • 6,856
1 vote
2 answers
2k views

How to match multiple case classes and extract same (-named) arguments?

Consider the following contrived example of implementing a unary & binary operations on real number expressions. abstract class DoubleE case class Negate(x: DoubleE) extends DoubleE case class ...
eold's user avatar
  • 6,012
0 votes
0 answers
128 views

Scala - restricting access to generic case classes

If I want a case class that cannot be manually constructed from outside a package, standard way would be something like this: case class Foo private[p](a:A,b:B) object Foo{ def apply(c:C) = { ...
User1291's user avatar
  • 7,890