Questions tagged [extractor]

151 questions
18
votes
4 answers

Why does opencv FREAK extractor remove so many keypoints, specifically using ORB detector

I am using OpenCV 2.4.3 c++ interface to find matching points between two images. The first attempt was using SURF. The only problem is the consuming time, so I tried the new FREAK extractor. Using SURF for detection and FREAK for description, I…
min.yong.yoon
  • 490
  • 4
  • 13
15
votes
1 answer

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] on the unapply line), trait StringDecoder[A] { …
Toby
  • 8,665
  • 6
  • 31
  • 56
14
votes
5 answers

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…
Dan Shryock
  • 305
  • 2
  • 9
12
votes
2 answers

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: Int, f: Int, g: Int, h: Int) extends…
vucalur
  • 5,847
  • 2
  • 26
  • 44
10
votes
6 answers

Scala: Pattern matching when one of two items meets some condition

I'm often writing code that compares two objects and produces a value based on whether they are the same, or different, based on how they are different. So I might write: val result = (v1,v2) match { case (Some(value1), Some(value2)) => "a" case…
Alex Black
  • 12,895
  • 15
  • 73
  • 97
9
votes
3 answers

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 extends Node case class Arc extends Node case class…
Ivan Poliakov
  • 1,505
  • 13
  • 19
9
votes
1 answer

Understanding pattern matching on lists

I've been playing around with Extractors lately and was wondering how the List extractors work especially this: List(1, 2, 3) match { case x :: y :: z :: Nil => x + y + z // case ::(x, ::(y, ::(z , Nil))) } Ok :: is used in the pattern, so I…
raichoo
  • 2,527
  • 20
  • 28
8
votes
5 answers

Scala, partial functions

Is there any way to create a PartialFunction except through the case statement? I'm curious, because I'd like to express the following (scala pseudo ahead!)... val bi = BigInt(_) if (bi.isValidInt) bi.intValue ... as a partial function, and…
aioobe
  • 383,660
  • 99
  • 774
  • 796
8
votes
1 answer

Pattern matching against Scala Map entries

Is there any Scala trick to enable pattern matching against map keys? In other words, I'd like to have an extractor that beside the Map instance accepted also a key value that would mean I want this pattern to match only if the matchable value is an…
Jiří Vypědřík
  • 1,288
  • 12
  • 24
7
votes
1 answer

Nested Scala matchers why Some(Some(1),1) can't match?

It seems that nested matching doesn't work, which is a strange limitation. An example of the behaviour follows: Some(Some(1),2) match { | case Some(Some(a),b) => a | case e => e | } :9: error: wrong number of arguments for : (x:…
Bryan Hunt
  • 3,265
  • 2
  • 22
  • 34
7
votes
1 answer

Why does a for-comprehension used with an extractor of type tuple result in a compile warning on `filter`?

Given the following code snippelt: import scala.util.Try def foo(x:Int) : (Int, String) = { (x+1, x.toString) } def main(args: Array[String]) : Unit = { val r1: Try[(Int, String)] = for { v <- Try { foo(3) } } yield v val r2:…
Martin Senne
  • 5,511
  • 6
  • 27
  • 46
6
votes
1 answer

Match order with an extractor

I defined a custom extractor to get the last element of the list, as in https://stackoverflow.com/a/6697749/1092910: object :+ { def unapply[A](l: List[A]): Option[(List[A], A)] = { if (l.isEmpty) None else Some(l.init,…
6
votes
1 answer

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.xs11, ..., x.xs1k) For implementation reasons, I…
Nicolas
  • 23,373
  • 4
  • 57
  • 64
6
votes
3 answers

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 there are already questions related to case…
7zark7
  • 9,633
  • 5
  • 35
  • 53
5
votes
1 answer

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 apply method in the companion object for Box is…
Marvin.Hansen
  • 1,060
  • 1
  • 9
  • 19
1
2 3
10 11