// I believe all of the below are fully nestable const foo = match (x) { // Basic concepts. This is all you need to actually know. `Symbol.match` // operates on this Object {}-style protocol in all cases. // object-style destructuring. x, y are bound. Just {val} => val None {} => ... // (see below for alternative None) // bind value to x, match with matcher. Toplevel reduntant; used for nesting Matcher {} as x => x // Syntax sugar extensions, all statically compile down to above. // Desugars to `String/Number/RegExp {}` but compilers can special-case. 'literal' => ... 42 => ... /regexp/ => ... // Regexp has Array-like matcher. // This desugars to RegExp {length: 2, 0: a, b: 2} /regexp/ [a, b] => ... // Desugars to Object {x, y} {x, y} as obj => ... // Desugars to Array {length: 2, 0: a, 1: b}. Array[Symbol.match] method enforces the "fail if wrong length" [a, b] => ... // Desugars to TypedArray {length: 2, 0: a, 1: b} TypedArray [a, b] => ... // `as` syntax allows omitting {} for matchers maybe? Matcher as x => ... // Plain variable matches without running a matcher. // imo, this doesn't need a first-class fallthrough. I think encouraging // people to have "fully qualified" matchers is important and // regular variables can be used for fallthrough just fine // Please no * nonsense plz _ => 'just a variable' other => console.log(other) // lol // equality matches done with guards other if other === 1 => 'other is 1' }