{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/6067","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/6067/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/6067/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/6067/events","html_url":"https://github.com/dotnet/roslyn/issues/6067","id":111826177,"number":6067,"title":"Proposal: Allowing patterns in more places","user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Discussion","name":"Discussion","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-10-16T12:56:56Z","updated_at":"2015-10-22T22:44:54Z","closed_at":null,"body":"Patterns in `match`, `switch` or `is` not only check if the pattern matches but also bind the variables to the target object. While the former only makes sense in the context of pattern matching, the latter would be useful in a wider context. There will be a specific syntax for this in local variable declarations but I suggest a way to use the deconstruction syntax, `case` *pattern*, in other places without changing the default behavior.\r\n```cs\r\n// method declaration\r\nvoid F(case (int a, int b)) {}\r\n\r\n// anonymous method\r\ndelegate(case (int a, int b)) {}\r\n\r\n// lambda expression\r\ncase (int a, int b) => {}\r\n\r\n// async lambda expression\r\nasync case(int a, int b) => {}\r\n\r\n// type annotated lambda expression\r\n(Foo case Bar bar) => {}\r\n\r\n// lambda expression with multiple parameters \r\n(case (int a, int b) whole_tuple, int c) => {}\r\n\r\n// lambda expression with implicitly typed parameters\r\n// note that presence of var in this case depends on the pattern specification\r\n(case (var a, var b) whole_tuple,  c) => {}\r\n\r\n// example\r\nfoo.Event += (case Foo sender, e) => { };\r\nfoo.Event += (case Foo(member), e) => { };\r\n\r\n// foreach variable declaration\r\nforeach(case (t1, t2) in list) {}\r\n\r\n// from clause\r\nfrom case (a,b) in list \r\nselect ..\r\n\r\n// let clause\r\nfrom t in list \r\nlet case (a,b) = t.Foo\r\nselect ...\r\n```\r\nAnd of course, out variable declarations (#6183)\r\n```cs\r\ntupleDictionary.TryGetValue(key, out case (a,b))\r\n```\r\nThe *pattern* used in these contexts must be complete or a warning occurs  (depending on the behavior regarding handling the completeness in `match` expressions) and if it fails a runtime exception would be thrown.\r\n\r\nYou should be able to apply an active pattern (#5718) along the way.\r\n\r\nAn additional feature here would be *overloading via patterns*:\r\n```cs\r\nvoid F(case Pattern1(a)) => ...\r\nvoid F(case Pattern2(a)) => ...\r\n```\r\nExample involving #6115:\r\n```cs\r\npublic override bool Equals(object) => false; // implicit case *\r\npublic override bool Equals(object case Foo foo) => Equals(foo);\r\n```\r\nActually all these methods will be merged into one method that contains a `match` or `switch`."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/150376823","html_url":"https://github.com/dotnet/roslyn/issues/6067#issuecomment-150376823","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/6067","id":150376823,"user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"created_at":"2015-10-22T22:44:54Z","updated_at":"2015-10-22T22:44:54Z","body":"@gafter I meant that this can be done without going through complexity of multiple methods. F# supports patterns in method parameters but doesn't support this one — which is common in functional languages like Haskell:\r\n```haskell\r\nisEmpty [] = true\r\nisEmpty _ = false\r\n```"}}