Re:JavaScript Pattern Matching Proposal
by codedokode on Wednesday April 25, 2018 @11:46AM
(#16922636)
It could look like this:
[ Parent
| on HN ]
Re:JavaScript Pattern Matching Proposal
by ThurmaUman on Wednesday April 25, 2018 @12:24PM
(#16923111)
so 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;
});
Re:JavaScript Pattern Matching Proposal
by masklinn on Wednesday April 25, 2018 @12:55PM
(#16923498)
> 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.
This 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.