Questions tagged [unapply]

37 questions
0
votes
2 answers

Using unapply defined in traits

I have a trait trait A { def doSomething(a: Seq[Int]): Seq[String] = { a.map { case AA(s) => s // want to use unapply defined in trait (this(AA) not allowed) case _ => "idc" } } def unapply(a:…
CodeMan
  • 45
  • 6
0
votes
1 answer

Unable to resolve unapply

object micro extends App { sealed trait FuncExpr sealed trait FuncSpecialize sealed case class Func(i:Int) extends FuncExpr sealed case class Cube(b:Boolean) extends FuncSpecialize object Cube { def unapply(arg:Func) :…
Tilman Zuckmantel
  • 643
  • 1
  • 6
  • 18
0
votes
2 answers

scala uanpply without parameter

I am a student who studies Scala in korea. I am learning about pattern matching and unapply methods. The thing I am confused about is that Emergency object has a parameter in unapply method. I can't know the reason when I don't put the parameter in…
dogyhbin2
  • 25
  • 6
0
votes
3 answers

Scala: Workaround for unparameterizable extractor

Since extractors cannot take custom parameters (as answered in Stack Overflow: Can extractors be customized...), I try to find an alternative way of solving the following problem. I have a lot of translations which can be combined. In my code…
ideaboxer
  • 3,863
  • 8
  • 43
  • 62
0
votes
1 answer

Playing with Nat without case classes

I just create a definition in scala for Naturals, and also a PLUS operation: abstract class Nat { def +(other:Nat):Nat = this match { case Zero => other case Succ(x) => x + Succ(other) } } object Zero extends Nat { override def…
Joselo
  • 93
  • 1
  • 8
0
votes
2 answers

How do I inherit shared code in a Scala unapply function?

I have Scala code with some boilerplate, and I figure it's Scala, so I must be doing something wrong. I need some help figuring out how to remove the redundancies. trait Number { val x: Int } case class EvenNumber(x: Int) extends Number object…
W.P. McNeill
  • 16,336
  • 12
  • 75
  • 111
0
votes
1 answer

Scala for comprehension unapplySeq

I have a object radExtractor{ def unapplySeq(row:HtmlTableRow):Option[List[String]]={ val lista = (for{ a<-row.getByXPath("td/span/a") ah= a.asInstanceOf[DomNode] if(ah.getFirstChild!=null) } yield…
Arneball
  • 359
  • 3
  • 10
1 2
3