pattern-matching Questions

2

I am currently learning about pattern matching algorithms and have come across these two algorithms. I have the following general ideas: KMP Compares text left-to-right Uses a failure array to s...
Thermosiphon asked 18/4, 2013 at 14:5

2

So I'm writing a simple method that sums up the first 3 or less ints in a list but i'm confused about the match patterns. I currently have let sums l = match l with | [] -> 0 | (h1::h2::h3::_...
Tillett asked 20/2, 2016 at 3:13

2

I came across this JS code snippet: function append(demo = "", file = "") { const extra = "ctl=1&embed=1"; if (demo && file) return `/${demo}/?file=${fil...
Angelicangelica asked 14/5, 2023 at 16:36

2

Solved

I would like to do some multiline matching with bash's =~ #!/bin/bash str='foo = 1 2 3 bar = what about 42? boo = more words ' re='bar = (.*)' if [[ "$str" =~ $re ]]; then echo "${BASH_REMATCH[1]...
Causeway asked 27/9, 2012 at 10:53

5

I have following data in table: +----------------------+----------------------------------------------------------+--------------+ | subscriber_fields_id | name | field_type | +-------------------...
Send asked 9/3, 2015 at 9:43

4

Solved

Is there a way to 'pull' data out of an Option? I have an API call that returns Some(HashMap). I want to use the HashMap as if it weren't inside Some and play with the data. Based on what I've read...
Cletis asked 25/11, 2020 at 0:44

13

How can I count the number of "_" in a string like "bla_bla_blabla_bla"?
Undulate asked 5/10, 2010 at 21:28

4

Solved

I downloaded the release candidate of JDK19 from here https://jdk.java.net/19/ to play a little bit with the new record patterns that were implemented there, but I'm encountering some issues. In my...
Evvie asked 20/9, 2022 at 13:57

14

Solved

I'm looking for a way to test whether or not a given string repeats itself for the entire string or not. Examples: [ '0045662100456621004566210045662100456621', # '00456621' '007299270072992700...
Ire asked 6/4, 2015 at 23:2

4

Solved

I like to use pattern-matching on a nullable int i.e. int?: int t = 42; object tobj = t; if (tobj is int? i) { System.Console.WriteLine($"It is a nullable int of value {i}"); } However, this r...
Misology asked 19/1, 2018 at 14:9

4

Solved

I want to apply filter on an iterator and I came up with this one and it works, but it's super verbose: .filter(|ref my_struct| match my_struct.my_enum { Unknown => false, _ => true }) I w...
Grime asked 29/8, 2014 at 21:51

1

Solved

Learning Scala 3. how can i make this code type-match and compile? trait Key { type Value } object Name extends Key { type Value = String } object Age extends Key { type Value = Int } type D...
Washerman asked 17/2, 2023 at 15:10

1

I'm trying to take an arbitrary tuple of Futures and return a tuple of the completed future's values, while providing a time limit for the completion of the futures. I'm trying to use Tuple's provi...
Sizar asked 16/2, 2023 at 4:36

1

Here is a simple example: object MatchErasedType { trait Supe { self: Singleton => type T1 lazy val default: T1 def process(v: Any): T1 = { v match { case vv: T1 => vv case _ =&gt...
Benevento asked 11/2, 2023 at 21:28

1

Solved

I'm trying to zip tuples together and use match types to get the exact type of the resulting zip. I have a match type and the function: type Z[A <: Tuple, B <: Tuple] <: Tuple = (A, B) ma...
Human asked 5/2, 2023 at 20:48

11

Solved

Is there a way to generate a number sequence in vi or Vim? For example, for an arbitrary range of lines i  through j (where i < j) in a file opened in Vim, is there a way to generate a number se...
Roasting asked 28/3, 2012 at 8:23

5

I'm learning about regular expression. I don't know how to combine different regular expression to make a single generic regular expression. I want to write a single regular expression which...
Pineda asked 9/2, 2017 at 11:53

3

Solved

The new structural pattern matching feature in Python 3.10 is a very welcome feature. Is there a way to match inequalities using this statement? Prototype example: match a: case < 42: print('L...
Opulence asked 25/10, 2021 at 14:57

5

I want to switch through many possible cases for x and there's one case (here x == 0) where I want to check the result of some additional code to determine what to do next. One possibility is to re...
Salmi asked 14/6, 2016 at 14:30

6

Solved

Everybody says that pattern matching is a great feature in functional languages. Why? Can't I simple use ifs and switch cases for everything? I'd like to understand the advantages of using patter...
Dartmouth asked 25/1, 2014 at 19:17

1

Solved

In rust you can do things like this: for n in 1..101 { let triple = (n % 5, n % 2, n % 7); match triple { // Destructure the second and third elements (0, y, z) => println!("First is `0...
Pierre asked 26/12, 2022 at 19:42

6

Solved

Consider this: loop { let data = match something() { Err(err) => { warn!("An error: {}; skipped.", err); continue; }, Ok(x) => x }; let data2 = match something_else() { Er...
Romilda asked 11/4, 2018 at 22:11

2

Solved

My table has 650M rows (according to a fast but decently precise estimate from a query I found here). It has a text column called receiver_account_id, and I need to be able to search those records ...
Flowery asked 11/11, 2022 at 23:31

4

Solved

With pgAdmin III, I can list all the databases on my postgresql server. But with pgAdmin, I can delete only 1 database at the time. It takes a lot of time to delete, for example, 30 databases, on...
Autoroute asked 27/7, 2016 at 23:40

16

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 '...
Cornerwise asked 15/1, 2010 at 8:45

© 2022 - 2024 — McMap. All rights reserved.