Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [pattern-matching]

Finding sequences of data that have a particular structure or matching specific criteria or rules. For character pattern defined by a regular expression, use the tag regular-expressions instead.

Filter by
Sorted by
Tagged with
2 votes
5 answers
2k views

Pattern Matching on Request Body for Routing an HTTP Request

In an HTTP application, I think about routing requests based not only on the path, but also based on the request body. For an example, think about the following two different body schemas for a PUT ...
Jonathan Herrera's user avatar
0 votes
1 answer
96 views

Matching supersets

In my application I have requests and items, each of which are associated with property tuples (key value pairs, where keys can be repeated) stored in a Postgres database. The goal is to find a single ...
flakes's user avatar
  • 159
0 votes
1 answer
73 views

Extending TypeScript while being futureproof [closed]

C#10 Has extended the property pattern ability, I think it began since #7 EG: { Car: { Interior: pattern } } Meaning you can do some nice pattern matching even in if statements if (car_var is ...
Pogrindis's user avatar
  • 109
5 votes
4 answers
191 views

Are there known constructs for two-way string pattern matching?

I've often come across situations where pattern matching in a string is formalized, but the reverse is not. Say I invent a new string pattern that can be expressed by regex /([0-9a-z])*:([0-9a-z])*@([...
Jonathan Allard's user avatar
2 votes
2 answers
3k views

How to find matching profiles?

I'm developing backend for a dating app, in which each user has a profile of his/her characteristics a profile of ideal match's characteristics There are dozens of characteristics like gender, ...
Babr's user avatar
  • 139
2 votes
2 answers
358 views

Pattern Matching in OO code

I have a situation where I need to model objects that don't share common attributes but represent same logical entity. Now, based on their type they will have different attributes (properties). To ...
Michael's user avatar
  • 183
1 vote
1 answer
53 views

Managing cache when matching datas

I'm retrieving values from 3 tables in database and trying to make them match. I was wondering how I could manage cache in an elegant way. I can't change the database structure even though one of the ...
FooBar's user avatar
  • 13
2 votes
1 answer
139 views

Architectural considerations for frequently matching similar users

I've been trying to design a backend architecture to a SPA that satisfies the following: user constantly answer yes/no questions (ex: tinder swipe cards) The application calculates each user's ...
vapurrmaid's user avatar
0 votes
1 answer
236 views

Sequence matching problem is complicated, how can I break it down into easier smaller pieces?

I have two lists: 1: 1) A abc 2) A def 3) A ghi 4) B jkl 5) B mno 6) C fzy 7) C xxa 2: 1) vsf 2) jkl 3) fzy 4) xxa 5) xyz 6) mno 7) def 8) abc I am trying to match each of the continuous ...
sigil's user avatar
  • 363
3 votes
1 answer
4k views

Best method for Pattern Matching on Binary String?

I need to search a long string of binary string data (couple of megabytes worth of binary digits) for patterns of binary digits. There are about 100 000 different patterns to search for. Each is a ...
user289944's user avatar
5 votes
2 answers
945 views

Avoiding instanceof for recursive data types

I have written a simple class hierarchy to represent terms in Scala. Terms are recursive data types, e.g., a Sum and a Multiplication consist of the left-hand-side (lhs), which is a Term, and the ...
helios35's user avatar
  • 159
1 vote
5 answers
2k views

Representing different method results via the return type in C#

I am looking at a problem where a method can fail in a predictable way. For now I think that exceptions might not be a good way to represent some of the failures (I may be wrong on that). In any case ...
Stilgar's user avatar
  • 1,514
6 votes
3 answers
3k views

Search for similar vectors, based on elementwise difference

I understand that there is a thread discussing a similar issue here: How to efficiently search a set of vectors for a vector which is the closest match But my problem is slightly different - and ...
Ziqi's user avatar
  • 163
2 votes
0 answers
185 views

combine reader monad with choice

I have this two types open FSharpx open FSharpx.Reader type First = { Name: string Items: string list } type Second = { Name: string Numbers: int list } Using a Reader monad ...
fra9001's user avatar
  • 121
2 votes
1 answer
107 views

F# - Associating a function with the matching type of object

Let's say I'm programming a chess game. At some point I have to check, which moves are valid for a given piece. What would be the proper way to select the correct pathfinding function for a given ...
user avatar
3 votes
1 answer
105 views

Pattern matching events with arbitrary structure

My team implemented an alert broker system. The way it works is this: Event sources generate events, with mostly arbitrary structure, and the broker listens to them. Users go to the broker and use an ...
user avatar
3 votes
0 answers
225 views

String Pattern Matching from Lookup Table - Non-Exponential Solution?

Given the problem... Given a String comprising of non-alhpabetical symbols, and a Lookup Table where a subset of those symbols may equate to a single alphabetical character, output all possible ...
Kevin's user avatar
  • 131
10 votes
5 answers
6k views

Idiomatic pattern matching equivalent in Java

I'm building a simulator which parses some events from STDIN and "runs" them. My background is mostly functional programming these days, so it seemed natural to do something like this: data Event = ...
closeparen's user avatar
5 votes
3 answers
3k views

How to report multiple errors as a result of validation?

I have a class that transforms a complex model, for example an abstract syntax tree or intermediate model. The model can be either valid, invalid or partially invalid, i.e. it contains errors but some ...
user3998276's user avatar
0 votes
1 answer
21 views

Comparing articles from various web-stores

Today I had the idea to write a program that compares the prizes between different web-stores. The key question I am asking myself is how to find (with a high probability) the same article on another ...
Bobface's user avatar
  • 123
3 votes
2 answers
176 views

Algorithm to identify degree of similarity based on prior categorization

I am working with digital images that people have manually categorized on a number of parameters. I want to be able to find images that are similar or dissimilar based on certain categories. For ...
user1594322's user avatar
1 vote
2 answers
194 views

Multi-pattern matching

I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you ...
Rui Pedro Caldeira's user avatar
4 votes
1 answer
255 views

Pattern matching against two similar types

What is the best way to handle pattern matching in the following situation? sealed trait Metadata final case class Metadata1() extends Metadata final case class Metadata2() extends Metadata final ...
MI3Guy's user avatar
  • 250
1 vote
1 answer
86 views

Why try to match for nth negatives, as opposed to matching lesser positives?

My Title clearly indicated my lack of understanding about the core concept for pattern matching - specifically using .HTACCESS to block Bad-Bots from accessing a site, which they do in order to crawl ...
user avatar
1 vote
1 answer
250 views

Measure and locate areas of similar value in an image

I saw this picture online and wanted to see if I could create an algorithm to give ordinary images an effect like this: http://justinlivi.net/wp-content/uploads/2011/01/Living_In_Digital.jpg My idea ...
user3525258's user avatar
10 votes
2 answers
3k views

Why can't the Scala compiler give pattern matching warning for nonsealed classes/traits?

If I use an unsealed trait or abstract class in Scala and then use pattern matching, I wonder, does the compiler not know at compile time for this particular patternmatch what possible implementations ...
valenterry's user avatar
  • 2,429
0 votes
4 answers
2k views

Haskell's ':' operator

I am currently studying about pattern matching in Haskell from here. The author gives an example of the implementation of "head" function (which returns the first element of a list) as following: ...
Michael's user avatar
  • 213
3 votes
1 answer
355 views

Efficient Code Design for Pattern Search Using a Singleton Pattern

I am having difficulty figuring out an efficient (thread-safe) code design for the following problem. I have been at it for some time now and would really appreciate some advice and input on how best ...
Zeos's user avatar
  • 185
7 votes
1 answer
2k views

How do you make decorators as powerful as macros?

Quick background: I am designing a Pythonic language that I want to be as powerful as Lisp while remaining easy to use. And by "powerful", I mean "flexible and expressive". I've just been introduced ...
Gavin D. Howard's user avatar
12 votes
1 answer
8k views

Pattern matching in Clojure vs Scala

What are the key differences between pattern matching in these two languages? I am not referring to syntax, but capability, implementation details, range of use cases and necessity. Scala ...
kurofune's user avatar
  • 290
27 votes
4 answers
6k views

Is pattern-matching against types idiomatic or poor design?

It seems like F# code often pattern matches against types. Certainly match opt with | Some val -> Something(val) | None -> Different() seems common. But from an OOP perspective, that looks ...
Larry OBrien's user avatar
  • 4,977
5 votes
2 answers
404 views

Is it possible (and practical) to search a string for arbitrary-length repeating patterns?

I've recently developed a huge interest in cryptography, and I'm exploring some of the weaknesses of ECB-mode block ciphers. A common attack scenario involves encrypted cookies, whose fields can be ...
Louis Thibault's user avatar
6 votes
2 answers
3k views

Data structure for pattern matching

Let's say you have an input file with many entries like these: date, ticker, open, high, low, close, <and some other values> And you want to execute a pattern matching routine on the entries(...
alvonellos's user avatar
1 vote
1 answer
791 views

How to implement string matching based on a pattern

I was asked to build a tool that can identify if a string match a pattern. Example: {1:20} stuff t(x) {a,b,c} would match: 1 stuff tx a 20 stuff t c It is a sort of regex but with a different ...
Vincent Rischmann's user avatar
1 vote
3 answers
2k views

Programming language with pattern matching in trees [closed]

I'd like to prototype a computer algebra system. An equation would be represented by a tree and rules would be defined - similarly to mathematical axioms - by specifying a pattern (in the tree) and a ...
Gere's user avatar
  • 2,191
3 votes
1 answer
2k views

Tineye.com search algorithm?

I was wondering how does tineye carry a search. Does it store all the images and then extracts exif data? Which in turn must be stored in a database and queried against. So probably it is using some ...
Marin's user avatar
  • 403