pattern-matching Questions
1
Solved
If I try to build the following code:
fn main () {
let my_val: u32 = 42;
match my_val % 2 {
0 => println!("We're even now"),
1 => println!("Well, that's odd"),
}
}
...
Berl asked 11/9 at 9:11
3
Solved
I'm trying to get a sense of the relationship between view patterns and pattern guards in GHC. Pattern guards seem quite intuitive, while view patterns seem a bit confusing. It kind of looks like v...
Potty asked 24/12, 2013 at 21:17
6
Solved
In my code, I need to distinguish a list of records from a list of lists of records. The existing code does it like so:
if isinstance(input_var, list):
if len(input_var) > 0:
if all(isinstance...
Granitite asked 3/4 at 15:8
3
I have a Java 17 project using Eclipse 2022-03 and OpenJDK 17:
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (bui...
Crowder asked 13/6, 2022 at 0:25
3
Solved
I have Java 19, and I am attempting to do some simple pattern-matching on a record that I created. However, Java is giving me a very confusing compilation error. Here is the simplest example I coul...
Subtenant asked 2/1, 2023 at 2:46
6
Solved
What is the command to match brackets in Emacs (the equivalent of the % command in Vim)?
Swirly asked 4/11, 2008 at 10:59
3
Solved
I have this code to check whether or not a variable is a number or a Vector2:
def __mul__(self, other):
match type(other):
case int | float:
pass
case Vector2:
pass
If I run this, I get
Synta...
Waistline asked 23/4, 2022 at 18:24
3
Solved
I have a while let loop which goes over an iterator of Result and uses pattern matching; it goes over the iterator until it either hits an Err or the Ok's value is an empty string:
while let Some(...
Voluptuary asked 26/10, 2016 at 18:4
3
Solved
I need to list all files in the current directory (.) (including all sub directories), and exclude some files as how .gitignore works (http://git-scm.com/docs/gitignore)
With fnmatch (https://docs...
Vaden asked 10/8, 2014 at 14:31
3
Solved
The tutorial shows some very basic examples of pattern matching, such as matching over an integer to emulate a c-style switch statement. The tutorial also shows how to do basic destructuring over a...
Macfarlane asked 14/2, 2012 at 19:16
4
The man page says that case statements use "filename expansion pattern matching".
I usually want to have short names for some parameters, so I go:
case $1 in
req|reqs|requirements) TASK="Function...
Clova asked 29/12, 2010 at 13:57
6
Solved
Ruby has a fairly powerful case..when..else construct for when you need to match criteria against a single variable. What is the "canonical" way to match criteria against multiple variables without...
Danseuse asked 1/2, 2011 at 3:16
30
Anyone know a good and effective way to search/match for a byte pattern in an byte[] array and then return the positions.
For example
byte[] pattern = new byte[] {12,3,5,76,8,0,6,125};
byte[] to...
Lawtun asked 12/11, 2008 at 9:52
4
Solved
I am trying to match a type in Python 3.10 using the console:
t = 12.0
match type(t):
case int:
print("int")
case float:
print("float")
And I get this error:
File "&l...
Swear asked 22/1, 2022 at 17:9
3
Solved
I want to trigger an AWS lambda function via EventBridge every time an S3 Object is created in an S3 bucket called "mybucket", but ONLY if its name/key ends with a ".csv"-suffix...
Kelby asked 15/12, 2022 at 11:51
6
In C# 7.1 the below is valid code:
object o = new object();
switch (o)
{
case CustomerRequestBase c:
//do something
break;
}
However, I want to use the pattern switch statement in the followi...
Hanshansard asked 3/12, 2018 at 16:25
4
Solved
I have the following:
serv match {
case "chat" => Chat_Server ! Relay_Message(serv)
case _ => null
}
The problem is that sometimes I also pass an additional param on the end of the ser...
Antislavery asked 19/3, 2012 at 12:42
1
Solved
I started to play with the new Java 21 feature - pattern matching.
public class Main {
public static void main(String[] args) {
RecordB recordB = new RecordB(true);
switch(recordB) {
case Re...
Curculio asked 27/9, 2023 at 16:46
1
Solved
Java 21 record patterns promises the introduction of destructuring to the Java language. However, it seems to be tightly coupled to pattern matching that can only be used as part of instanceof comp...
Plater asked 22/9, 2023 at 12:53
4
Solved
Let's say that I have a trait, Parent, with one child, Child.
scala> sealed trait Parent
defined trait Parent
scala> case object Boy extends Parent
defined module Boy
I write a function t...
Becki asked 4/2, 2015 at 17:13
5
I am working on a time series data. The data available is multi-variate. So for every instance of time there are three data points available.
Format:
| X | Y | Z |
So one time series data in a...
Ledaledah asked 20/5, 2016 at 14:48
2
I have a 3D lattice with a unit cell (i.e. the minimum repeating unit) of 16 points. Since it's a 3D lattice, it is periodic in all 3 dimensions (x, y, z). In detail, the unit cell looks like this:...
Winny asked 6/8, 2023 at 20:18
3
Solved
I want a pattern with letters and numbers only.
This is how I do it...
JavaScript file:
var pattern_checked = checkPattern();
function checkPattern(){
var elem = document.getElementById("name...
Barty asked 30/5, 2017 at 7:35
1
Solved
What is the difference between two periods and underscore in this case:
let a = Some("a");
match a {
Some(_) => println!("we are in match _"),
_ => panic!(),
}
matc...
Aporia asked 14/6, 2023 at 18:1
10
Solved
I'm reading about functional programming and I've noticed that Pattern Matching is mentioned in many articles as one of the core features of functional languages.
Can someone explain for a Java/C+...
Altarpiece asked 23/3, 2010 at 17:57
1 Next >
© 2022 - 2024 — McMap. All rights reserved.