pattern-matching

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 (Some(value), None)) => "b" case (None, Some(value)) => "b" case _ = > "c" } Thos...

Find sequences of digits in long integers efficiently

Is it possible to find a defined sequence in an integer without converting it to a string? That is, is it possible to do some form of pattern matching directly on integers. I have not thought of one but I keeping thinking there should be a mathematical way of doing this. That's not to say it is more efficient. (edit) I actually what num...

Pattern matching with multiline XML case

I must be doing some stupid mistake. I have a server that returns the XML <a><b>123</b></a> and now I would like to match against that XML. So I write something like xml match { case <a><b>{_}</b></a> => true } This works as long as I do not have to deal with multi-line XML literals. So the important thing is that the server sends m...

Comparing two JPEG IMAGES and displaying differences

Images are of the same object taken at different time intervals. Software solutions - to be implemented in hardware. High rate of performance most important in hardware implementation ...

Matching sub-classes of case classes in Scala

Why does this fail to compile (or work?): case class A(x: Int) class B extends A(5) (new B) match { case A(_) => println("found A") case _ => println("something else happened?") } The compiler error is: constructor cannot be instantiated to expected type; found : blevins.example.App.A required: blevins.example.Ap...

Using jQuery's Sizzle Engine to find a class (advanced)

What I am attempting to do is see if a jQuery object (or even DOM element for that matter) contains a particular class using the same selectors as the Sizzle engine. jQuery publicly exposes Sizzle with the following: jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.filters; jQuery.unique = Sizzle.uni...

Find common prefix of strings

I am having 4 strings: "h:/a/b/c" "h:/a/b/d" "h:/a/b/e" "h:/a/c" I want to find the common prefix for those strings, i.e. "h:/a". How to find that? Usually I'd split the string with delimiter '/' and put it in another list, and so on. Is there any better way to do it? ...

Pattern-matching Seq's in Haskell

Pattern matching is one of the most elegant Haskell features. I've been working on a project recently where I need a queue data structure so I'm using Data.Sequence. However, it looks like I have to give up the elegance of pattern matching and resort to guards: floodFillWorker :: Image -> RGBAColor -> Double -> PixelQueue -> Image fl...

detect object in image,how they did it. I think it is unbelieveable

this picture is download from a website,the team show their research result like this. I want to know how they did it, some body know tell me I will be appreciate. thank you ...

How can I match a function signature without getting type erasure compiler warnings in Scala.

Hi scala gurus Can anyone re-write this code to do the same thing but without any compiler warnings please:- object TestTypeErasure { def main(args:Array[String]) { def myFunction(myObject:Any):Boolean = { true } val myVariable: (Any => Boolean) = myFunction myVariable match { case function:(Any => Boo...

who have used PedestrianDetectionHoG_NET2005 I need to know the configure process

this object detect soft ware is good to detect object and recognize them. I want to learn it, I download it and download the lib it required such as blitz0.9 boost1.41 and opencv 2.0,but when I run the software it have too many problem . I think maybe the configure is not right that cause the errors,I want to know who have run the softwa...

F# pattern matching on types of tuples

I have a curried function that I'd like it to support different types of parameters, that are not on a inheritance relationship: type MyType1 = A | B of float type MyType2 = C | D of int What I tried to do is: let func x y = match (x, y) with | :? Tuple<MyType1, MyType1> -> "1, 1" | _ -> "..." However this is not possib...

Pattern matching style in C++?

I love Haskell style pattern matching. I have my C++ code as follows: ObjectPtr ptr; if(ptr.isType<Foo>()) { // isType returns a bool Ptr<Foo> p = ptr.convertAs<Foo>(); // convertAs returns a Ptr<Foo> ...... } if(ptr.isType<Bar>()) { Ptr<Bar> p = ptr.convertAs<Bar>(); ...... } Now, are there any macros I can do define to simp...

Programatically extract pattern from image file and / or PSD

I often have to extract a pattern from a PSD to make an image to be used with XHTML and CSS. I have often just made a guess in Photoshop, and then had to correct my guesses a few time after. It seems cumbersome. Is there... Techniques for extracting a pattern from a Photoshop file with the selector tool? A Photoshop plugin perhaps th...

Case Insensitive Pattern Matching over String Lists

I'm trying to parse command line arguments in an F# application. I'm using pattern matching over parameters list to accomplish it. Something like: let rec parseCmdLnArgs = function | [] -> { OutputFile = None ; OtherParam = None } | "/out" :: fileName :: rest -> let parsedRest = parseCmdLnArgs rest ...

Haskell pattern matching - what is it?

What is pattern matching in Haskell and how is it related to guarded equations? I've tried looking for a simple explanation, but I haven't found one. EDIT: Someone tagged as homework. I don't go to school anymore, I'm just learning Haskell and I'm trying to understand this concept. Pure out of interest. ...

What is the sprintf() pattern to output floats without ending zeros?

I want to output my floats without the ending zeros. Example: float 3.570000 should be outputted as 3.57 and float 3.00000 should be outputted as 3.0 (so here would be the exception!) ...

Fast two-dimensional pattern matching

Consider a two-dimensional grid (the usual lattice in the plane). For my purposes, a pattern or arrangement is an assignment of the numbers 1 and 2 to some connected subset of the grid points. For example, the following shows three separate arrangements: .......1.....1.... .222...2.....12... .111...2.....2.... .222...22...12211. ........

How to convert a csv list (horizontal) from vertical name value pair set

I have a list like this: GTPYANJ 695848 GTPYANJ 27811 FPORTAL3 432532 I want to turn it into this using regular expressions: GTPYANJ,695848,27811 FPORTAL3,432532 Suggestions? ...

Javascript string matching pattern help

Hi guys, i need to find few words or matching pattern using a Javascript. this is the requirement. i have a string like this, Here is a quick guide for the next time you reach for your favorite oil and some other topics and i need to match this string against a string like this favorite oil and some other topics can be based...