{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/35","repository_url":"https://api.github.com/repos/tc39/proposal-pattern-matching","labels_url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/35/comments","events_url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/35/events","html_url":"https://github.com/tc39/proposal-pattern-matching/issues/35","id":241463975,"number":35,"title":"Proposal to add an ExpressionPattern","user":{"login":"aem","id":1909883,"avatar_url":"https://avatars0.githubusercontent.com/u/1909883?v=4","gravatar_id":"","url":"https://api.github.com/users/aem","html_url":"https://github.com/aem","followers_url":"https://api.github.com/users/aem/followers","following_url":"https://api.github.com/users/aem/following{/other_user}","gists_url":"https://api.github.com/users/aem/gists{/gist_id}","starred_url":"https://api.github.com/users/aem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aem/subscriptions","organizations_url":"https://api.github.com/users/aem/orgs","repos_url":"https://api.github.com/users/aem/repos","events_url":"https://api.github.com/users/aem/events{/privacy}","received_events_url":"https://api.github.com/users/aem/received_events","type":"User","site_admin":false},"labels":[{"id":639413602,"url":"https://api.github.com/repos/tc39/proposal-pattern-matching/labels/design%20idea","name":"design idea","color":"84b6eb","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-07-08T16:28:50Z","updated_at":"2017-08-21T08:05:13Z","closed_at":null,"body":"I think when working with primitives, an ExpressionPattern will be enormously helpful. Take the following trivial example code:\r\n```javascript\r\nif (x < 5) {\r\n  console.log(\"small\");\r\n} else if (x < 10) {\r\n  console.log(\"medium\");\r\n} else {\r\n  console.log(\"large\");\r\n}\r\n```\r\n\r\nBy having an ExpressionPattern this code is greatly simplified:\r\n```javascript\r\nmatch (x) {\r\n  < 5: console.log(\"small\")\r\n  < 10: console.log(\"medium\")\r\n  else: console.log(\"large\")\r\n}\r\n```\r\n\r\nAn alternate syntax (which, admittedly, would significantly impact this proposal) would be to auto-bind to a generic value (like `it` in [Kotlin](https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter)), allowing expressions like this:\r\n```javascript\r\nmatch (x) {\r\n  it < 5: console.log(\"small\")\r\n  it < 10: console.log(\"medium\")\r\n  else: console.log(\"large\")\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/comments/323674968","html_url":"https://github.com/tc39/proposal-pattern-matching/issues/35#issuecomment-323674968","issue_url":"https://api.github.com/repos/tc39/proposal-pattern-matching/issues/35","id":323674968,"user":{"login":"freddi301","id":1537394,"avatar_url":"https://avatars2.githubusercontent.com/u/1537394?v=4","gravatar_id":"","url":"https://api.github.com/users/freddi301","html_url":"https://github.com/freddi301","followers_url":"https://api.github.com/users/freddi301/followers","following_url":"https://api.github.com/users/freddi301/following{/other_user}","gists_url":"https://api.github.com/users/freddi301/gists{/gist_id}","starred_url":"https://api.github.com/users/freddi301/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freddi301/subscriptions","organizations_url":"https://api.github.com/users/freddi301/orgs","repos_url":"https://api.github.com/users/freddi301/repos","events_url":"https://api.github.com/users/freddi301/events{/privacy}","received_events_url":"https://api.github.com/users/freddi301/received_events","type":"User","site_admin":false},"created_at":"2017-08-21T08:05:13Z","updated_at":"2017-08-21T08:05:13Z","body":"I think here Symbol.matches should be used.\r\nIt gives less dense code but more clear and doesn't complicate syntax\r\n\r\n```javascript\r\nconst lessThan = x => ({[Symbol.matches]: y => y < x });\r\nmatch (x) {\r\n  lessThan(5): console.log(\"small\"),\r\n  lessThan(10): console.log(\"medium\"),\r\n  intentionRevealingName(curriedArg): console.log(\"42\"),\r\n  else: console.log(\"large\")\r\n}\r\n```"}}
{"actor":{"display_login":"freddi301"}}