1

The title is my question. Specifically, wildcards are important when matching against values in tuples.

In OCaml it is possible:

match x with 
   (3, _) -> 5 | 
   (_, 4) -> 7 | 
   (4, 5) -> 6;; 

A 'switch' contruct, that allows matching against tuple values without wildcards is not useful. In Ceylon, I think the switch is broken ;-).

Lii
  • 11,553
  • 8
  • 64
  • 88
Malelago
  • 31
  • 3

1 Answers1

1

No, this is not yet possible. You can match a tuple literal (case ([1, 2])), and you can use destructuring (case ([Integer i, Integer j]), which is just syntax sugar for case (is [Integer, Integer]) { value [i, j] = x; … }), but you can’t use literal values to match in a destructuring pattern.

Lucas Werkmeister
  • 2,584
  • 1
  • 17
  • 31