Title: Pattern Matching Support · Issue #165 · microsoft/TypeScript · GitHub
Open Graph Title: Pattern Matching Support · Issue #165 · microsoft/TypeScript
X Title: Pattern Matching Support · Issue #165 · microsoft/TypeScript
Description: I've seen some short notions about pattern matching on code plex, but no serious discussions around it. As I'm a big fan of it, I've written up some small examples on how I think pattern matching could look in TypeScript. This is by far ...
Open Graph Description: I've seen some short notions about pattern matching on code plex, but no serious discussions around it. As I'm a big fan of it, I've written up some small examples on how I think pattern matching c...
X Description: I've seen some short notions about pattern matching on code plex, but no serious discussions around it. As I'm a big fan of it, I've written up some small examples on how I think patter...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/165
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pattern Matching Support","articleBody":"I've seen some short notions about pattern matching on code plex, but no serious discussions around it. As I'm a big fan of it, I've written up some small examples on how I think pattern matching could look in TypeScript.\n\nThis is by far no complete specification, just some ideas that I want to bring forward and have a little discussion around.\n## Function Overloading\n\n``` ts\n// Pattern matching on functions\n\nfunction pickCard {\n (x: {suit: string; card: number; }[]): number {\n\n var pickedCard = Math.floor(Math.random() * x.length);\n return pickedCard; \n\n }\n (x: number): {suit: string; card: number; } {\n\n var pickedSuit = Math.floor(x / 13);\n return { suit: suits[pickedSuit], card: x % 13 };\n\n }\n} \n```\n\n``` js\n// Translation of functions.ts using sparkler\n// https://github.com/natefaubion/sparkler\n\nfunction pickCard(x) {\n [...{ suit @ String, card @ number }] => {\n var pickedCard = Math.floor(Math.random() * x.length);\n return pickedCard; \n }\n x @ Number => {\n var pickedSuit = Math.floor(x / 13);\n return { suit: suits[pickedSuit], card: x % 13 };\n }\n} \n```\n## `Match` statement\n\n``` ts\n// Pattern matching using match\n\nfunction whoami (x: any): string {\n\n match x {\n case { name: string, type: 'person' }: \n return 'Person: ' + name;\n\n case { name: string, type: 'animal' }: \n return 'Animal: ' + name;\n\n default: \n return 'Unkown you';\n }\n} \n```\n\n``` js\n// Pattern matching using match translated\n\nfunction whoami (x) {\n\n match x {\n case { name @ String, type: 'person' }: \n return 'Person: ' + name;\n\n case { name @ String, type: 'animal' }: \n return 'Animal: ' + name;\n\n default: \n return 'Unkown you';\n }\n\n} \n```\n","author":{"url":"https://github.com/dignifiedquire","@type":"Person","name":"dignifiedquire"},"datePublished":"2014-07-21T19:42:28Z","url":"https://github.com/microsoft/TypeScript/issues/165"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c4568ded-9d6c-a603-fbfc-5b138afe1612 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A994:2463BD:2A568AA:3611679:6B019C0B |
| html-safe-nonce | f2d40d7ce3084cbea5d773225e2c4ad0db525cc0732a23f1bcff11989e9df763 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTk0OjI0NjNCRDoyQTU2OEFBOjM2MTE2Nzk6NkIwMTlDMEIiLCJ2aXNpdG9yX2lkIjoiNjc3OTkwMzg1OTA2NzI5Njc4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2b1bd0a780942b00940e3d2e053d6cdba32bd6c6d2adc43658d710a6b06547f1 |
| hovercard-subject-tag | issue:38337284 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Microsoft/TypeScript/165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/85345a25aebbdf61024ccebb50cbbaf6c491ebcf7654ea62a2e851bd8d75855f/microsoft/TypeScript/issues/165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/85345a25aebbdf61024ccebb50cbbaf6c491ebcf7654ea62a2e851bd8d75855f/microsoft/TypeScript/issues/165 |
| og:image:alt | I've seen some short notions about pattern matching on code plex, but no serious discussions around it. As I'm a big fan of it, I've written up some small examples on how I think pattern matching c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dignifiedquire |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width