Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 used in the case of a regular expression or some other string pattern like construct, but hopefully it explains what I'm looking for:

def someExtractorBuilder(arg:Boolean) = new {
  def unapply(s:String):Option[String] = if(arg) Some(s) else None
}

//I would like to be able to use something like this 
val {someExtractorBuilder(true)}(result) = "test"
"test" match {case {someExtractorBuilder(true)}(result) => result }

//instead I would have to do this:
val customExtractor = someExtractorBuilder(true)
val customExtractor(result) = "test"
"test" match {case customExtractor(result) => result}

When just doing a single custom extractor it doesn't make much difference, but if you were building a large list of extractors for a case statement, it could make things more difficult to read by separating all of the extractors from their usage.

I expect that the answer is no you can't do this, but I thought I'd ask around first :D

like image 621
Dan Shryock Avatar asked Mar 09 '10 18:03

Dan Shryock


1 Answers

Parameterising extractors would be cool, but we don't have the resources to implement them right now.

like image 84
Adriaan Moors Avatar answered Sep 23 '22 15:09

Adriaan Moors