Questions tagged [extractor]
164 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
17
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
- 345
- 2
- 9
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
- 9,523
- 8
- 36
- 59
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
- 6,007
- 3
- 29
- 46
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…

waterlooalex
- 13,642
- 16
- 78
- 99
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
- 2,245
- 1
- 18
- 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,557
- 21
- 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
- 413,195
- 112
- 811
- 826
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,324
- 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,685
- 2
- 24
- 36
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,939
- 6
- 30
- 47
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,…

John Salvation
- 63
- 3
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
- 24,509
- 5
- 60
- 66
6
votes
2 answers
How to get access token with JMeter JSON Extractor and use it?
I'm trying to extract access token from the body response and use it in Header Manager for authorization.
The response of the first request is
Response
Then I use regular expression for extracting the token
Json Extractor
Then I enter a variable…

Andrew Chichick
- 89
- 1
- 3
- 8
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
- 10,015
- 5
- 39
- 54