3 ms·
I think match cases should be functions, since you have built those anyway. So instead of match (x) { expr... } you would have something like match(x, [ fn...
by metalrain 8y ago
I think match cases should be functions, since you have built those anyway.
So instead of match (x) { expr... } you would have something like
match(x, [ fn... ]) or
match(x) { name: fn, name2: fn2 }
where fn is like (objectToMatch) => { expr }
- codedokode 8y agoIt could look like this: var x = match (response) { case { status:200 }: true; case { status: 404 }: false; case Number: 0; case SomeClass: 1; default: -1; };
- ThurmaUman 8y agoso make switch first class? var x = (switch(true){ case response === { status: 200 }: return true; case response === { status: 404 }: return false; case response === Number: return 0; case response === SomeClass: return 1; default: return -1; });
- masklinn 8y ago> so make switch first class? No. That would make the actual switch statement a value, rather than make switches expressions. And your version is completely different as you make cases into guards rather than labels or patterns.
- kbp 8y agoThis would introduce a weird inconsistency with cases for match and cases for switch regarding fallthrough, though. If it's going to look like cases in a switch statement, it should act like them, for better or worse.