Live data from Hacker News

JavaScript Pattern Matching Proposal

github.com

11–20 of 254 posts

Re: JavaScript Pattern Matching Proposal

#11

I'm not familiar with the JS proposal process. Is this likely to become an official feature now that it's been proposed? If so what's the usual timeline of that look like? I would love to have this feature ASAP in the browser and/or Node.js and am eager to find out when that will be possible.

Yeah, I think that's essentially the idea. However the longer part is getting the support native in the browsers. Tools like babel will most likely provide some form of support before the browser does.

Re: JavaScript Pattern Matching Proposal

#12

Could someone please explain what this could be used for ?

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.

Re: JavaScript Pattern Matching Proposal

#13
post #6

Pattern 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.

Re: JavaScript Pattern Matching Proposal

#14

I'm not familiar with the JS proposal process. Is this likely to become an official feature now that it's been proposed? If so what's the usual timeline of that look like? I would love to have this feature ASAP in the browser and/or Node.js and am eager to find out when that will be possible.

Someone will surely do a Babel plugin to use the syntax allowing you to try it before it becomes an official feature.

Linked in the readme: https://github.com/babel/babel/pull/7633

Re: JavaScript Pattern Matching Proposal

#16

I'm not familiar with the JS proposal process. Is this likely to become an official feature now that it's been proposed? If so what's the usual timeline of that look like? I would love to have this feature ASAP in the browser and/or Node.js and am eager to find out when that will be possible.

This is a Stage 0 proposal. Basically it means somebody with a connection to the TC39 (the committee in charge of the JavaScript standard) has thought this was a good enough idea to put together into a proposal.

In terms of chances of standardization, that's a step up from "Hey, I have a great idea", buy there are plenty of Stage 0 proposals that go nowhere because they lose steam.

I think the metric they look for is who is using the Babel plugin for it. If people are doing that, then they it has a better shot of progressing.

Stage 4 is the "this is getting standardized next time" stage

Re: JavaScript Pattern Matching Proposal

#17

I'm not familiar with the JS proposal process. Is this likely to become an official feature now that it's been proposed? If so what's the usual timeline of that look like? I would love to have this feature ASAP in the browser and/or Node.js and am eager to find out when that will be possible.

Someone will surely do a Babel plugin to use the syntax allowing you to try it before it becomes an official feature.

It's at the bottom of the proposal https://github.com/babel/babel/pull/7633

Re: JavaScript Pattern Matching Proposal

#18
post #6

Pattern 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.

Fair point. What I was trying to express was that it seems like the JS ecosystem has really been pushing and encouraging functional programming in a big way, which speaks to your idea that more people have experience with it.

Re: JavaScript Pattern Matching Proposal

#20

Could someone please explain what this could be used for ?

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?
Post reply on HN