Pattern matching?

Henrik Sommerland henrik.sommerland at gmail.com
Fri Jun 30 15:33:55 UTC 2017


I would pick === without a doubt.
One may consider providing some form of optional syntax to do this like {b
~: 5} but I think that the safe way should be the default way.
If the decision is made to support both strict comparisons and the silly
ones (I'm a bit biased :p ) there could beseveral ways to fix this.

Den 30 juni 2017 17:26 skrev "Sebastian Malton" <sebastian at malton.name>:

> A question though, would this be equivalent to == or === matching for
> specific values?
>
> Namely does {b: 5} match with a passed in object that has {b:'5'}?
>
> Sebastian
>
> *From:* henrik.sommerland at gmail.com
> *Sent:* June 30, 2017 11:22 AM
> *To:* sebastian at malton.name
> *Cc:* es-discuss at mozilla.org
> *Subject:* Re: Pattern matching?
>
> Yes :)
>
> This is roughly what I had in mind:
>
> match obj with
>   {a, b : 5} -> return a + b
>   {a, c : {d, e : true}} -> return a + d
>   'rof' -> return 'lol'
>
> Where the first clause matches if obj has the property a and the property
> b that has the value 5.
> The second clause works the same but recursively.
> And the third simply checks if obj is equal to 'rof'.
>
>
> Den 30 juni 2017 16:46 skrev "Sebastian Malton" <sebastian at malton.name>:
>
> Are you thinking kind of like Rust's match statement? I think that
> something like that would be quite a good addition.
>
> Sebastian
>
> *From:* henrik.sommerland at gmail.com
> *Sent:* June 30, 2017 9:55 AM
> *To:* es-discuss at mozilla.org
> *Subject:* Pattern matching?
>
> Why is there no support for pattern matching in JavaScript?
> I would guess that it has been proposed before, and if so why hasn't it
> been included?
>
> I have been thinking about it and I think it would integrate nicely into
> JavaScript.
> If it hasn't been proposed already I would propose it, and I would gladly
> look into it more and try to examine what kind of semantics would be
> suitable.
>
> Peace!
> --
> Henrik "TheGrandmother" Sommerland
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170630/29cce115/attachment.html>


More information about the es-discuss mailing list