All Questions
Tagged with extractor case-class
8
questions
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: ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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) = {
...