0
votes

Is it possible to use a tuple as a pattern in a switch statement?

In the sample code below I'd like to define a named constant to represent a pattern to match against, in this case the tuple (1,2)

let thing = 1
let otherThing = 2
let patternToMatchAgainst = (1,2)

switch (thing, otherThing) {
  case patternToMatchAgainst: break // Expression pattern of type '(Int, Int)' cannot match values of type '(Int, Int)'
  default: break
}
1

1 Answers

0
votes

You can try like this: case (patternToMatchAgainst.0,patternToMatchAgainst.1):