On Mon, Oct 5, 2015 at 9:00 AM, Benjamin Gruenbaum <[email protected]> wrote: > Well, I've personally thought about building a small pattern matching > library using the syntax, but that's hardly a general use case: > > ```js > match( > (x = 1) => doFoo(...) > (x = {y : 3}) => doBar(...) > ```
That's just syntax punning/abuse, not a real use-case. ^_^ > However, there are several use cases people mention. Here are the first > twofrom questions asking for this on StackOverflow in other languages: > > - Exposing functions in a module over a JSON API. If the caller omits > certain function arguments, return a specific error that names the specific > function argument that was omitted. If a client omits an argument, but > there's a default provided in the function signature, I want to use that > default. I'm confused. If the argument defaulted or not? If it's defaulted, omitting it isn't an error. If omitting it is an error, then there's no default, by definition. > - Building an ORM that uses the default values in the database and returns > correct error messages when an insert of a default value failed. What about that requires the knowledge of the defaulted value, rather than just the argument value? I *might* see a use-case here for knowing *whether or not the argument was defaulted*, so you can output a more helpful error message (saying that the default is wrong, rather than saying the passed value is wrong), but knowing the default value doesn't help there (unless it's a unique sentinel value, which defeats the point of default values in the first place). ~TJ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

