Isn't pattern matching interesting only in a strongly typed environment where the compiler can statically check that you are giving instructions for all possible cases?
JavaScript Pattern Matching Proposal
31–40 of 254 posts
Re: JavaScript Pattern Matching Proposal
#32Isn't pattern matching interesting only in a strongly typed environment where the compiler can statically check that you are giving instructions for all possible cases?
Re: JavaScript Pattern Matching Proposal
#33Re: JavaScript Pattern Matching Proposal
#34Re: JavaScript Pattern Matching Proposal
#35Re: JavaScript Pattern Matching Proposal
#36Earlier quoted context omitted.
Smooshes the evaluation of an object that can be many different shapes into an easy to understand operation. I think the HTTP response is a great example. It can have many status codes which can determine how you want to proceed with that response. If you've worked with handling HTTP responses, you've most likely implemented some version of a 'match' operation before.
Is not `switch` enough for this?
I need to look at it more closely, as some languages have matching be an expression, rather than a statement or block like the conventional switch.
It doesn't add something that you can't already do- tcomb and other libraries offer functions that mimic it- but it changes the way you can express certain ideas without needing them, in a way that is already familiar from other languages.
EDIT: yes, it does look like an expression, which means it can be used in many more places than a standard switch.
Re: JavaScript Pattern Matching Proposal
#37Interestingly, the match construct is an expression, which I don't think JavaScript has m/any of. Perhaps they could retroactively make if/else expressions, if that doesn't break back-compat.
Re: JavaScript Pattern Matching Proposal
#38Pattern matching seems to be very trendy/popular right now. It's a big jump from JS, but https://reasonml.github.io has very nice pattern matching that you can use, and it integrates with the JS ecosystem very nicely.
It's been "trendy" since the 70's. It's more that more people have experience with it and realize that pattern matching is like conditional statements on steroids.
It's been possible since the '70s but I've seen a lot more talking about it in the last 5-10 years.
Re: JavaScript Pattern Matching Proposal
#39Isn't pattern matching interesting only in a strongly typed environment where the compiler can statically check that you are giving instructions for all possible cases?
No, not at all. E.g. Erlang is built around pattern matching as a core feature even though it's an untyped language.