rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.58k stars 439 forks source link

Explore pattern matching for dicts #6592

Open zth opened 5 months ago

zth commented 5 months ago
let myDict = dict{
  "key1": "k1"
}

switch myDict {
| dict{"key1": k} => Console.log(`key1 value: ${k}`)
| _ => Console.log("Miss")
}
cometkim commented 5 months ago

It would be efficient somehow for permanent map/set structures, but not sure for dicts oh.. maybe I forgot to think about it in JS, it can simply be done with destructuring :sweat_smile: