All Questions
7
questions
17
votes
5
answers
1k
views
Can extractors be customized with parameters in the body of a case statement (or anywhere else that an extractor would be used)?
Basically, I would like to be able to build a custom extractor without having to store it in a variable prior to using it.
This isn't a real example of how I would use it, it would more likely be ...
16
votes
1
answer
439
views
Can a Scala "extractor" use generics on unapply?
Can't I use a generic on the unapply method of an extractor along with an implicit "converter" to support a pattern match specific to the parameterised type?
I'd like to do this (Note the use of [T] ...
5
votes
1
answer
938
views
How to use extractor in polymorphic unapply?
I don't really get this little thingy. I have an abstract class Box
with several sub-classes for different types. For example
abstract class Box
class StringBox(val sValue : String) extends Box
The ...
3
votes
1
answer
756
views
What is the time and space complexity of a Scala's head/tail extractor?
What is the time and space complexity for this:
def isPalindrome[A](x: Seq[A]): Boolean = x match {
case h +: middle :+ t => h == t && isPalindrome(middle)
case _ => true
}
Does it ...
1
vote
2
answers
128
views
Why can't I reuse "unapply" without repeating the method signature
The following Scala code compiles fine:
val f = (input: String) => Some("result")
object Extract {
def unapply(input: String): Option[String] = f(input)
}
val Extract(result) = "a string"
But ...
1
vote
1
answer
847
views
Is it possible to use implicit conversions for parameters to extractors (unapply) in Scala?
I have created a class called CaseInsensitive which wraps a string (see Implementing a string class that does case insensitive comparisions in Scala).
I've created a case class which has a member ...
0
votes
3
answers
356
views
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 ...