{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/716","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/716/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/716/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/716/events","html_url":"https://github.com/dotnet/csharplang/issues/716","id":240265577,"node_id":"MDU6SXNzdWUyNDAyNjU1Nzc=","number":716,"title":"Proposal: Not-null conditional operator","user":{"login":"tseemann-xematec","id":1820825,"node_id":"MDQ6VXNlcjE4MjA4MjU=","avatar_url":"https://avatars1.githubusercontent.com/u/1820825?v=4","gravatar_id":"","url":"https://api.github.com/users/tseemann-xematec","html_url":"https://github.com/tseemann-xematec","followers_url":"https://api.github.com/users/tseemann-xematec/followers","following_url":"https://api.github.com/users/tseemann-xematec/following{/other_user}","gists_url":"https://api.github.com/users/tseemann-xematec/gists{/gist_id}","starred_url":"https://api.github.com/users/tseemann-xematec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tseemann-xematec/subscriptions","organizations_url":"https://api.github.com/users/tseemann-xematec/orgs","repos_url":"https://api.github.com/users/tseemann-xematec/repos","events_url":"https://api.github.com/users/tseemann-xematec/events{/privacy}","received_events_url":"https://api.github.com/users/tseemann-xematec/received_events","type":"User","site_admin":false},"labels":[{"id":537024200,"node_id":"MDU6TGFiZWw1MzcwMjQyMDA=","url":"https://api.github.com/repos/dotnet/csharplang/labels/Discussion","name":"Discussion","color":"c2e0c6","default":false},{"id":545773793,"node_id":"MDU6TGFiZWw1NDU3NzM3OTM=","url":"https://api.github.com/repos/dotnet/csharplang/labels/Feature%20Request","name":"Feature Request","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2017-07-03T21:11:11Z","updated_at":"2018-12-27T21:51:19Z","closed_at":null,"author_association":"NONE","body":"When the value of a conditional expression is dependent on calling a function with a non-null argument, \r\nI often find myself writing the following somewhat repetitive code, using the conditional operator (?:)\r\n\r\n**return a?.b != null ? foo(a.b) : null;**\r\n\r\nBesides being a rather verbose expression, the repeated mentioning of \"null\" adds a lot of noise.\r\n\r\nIt would be nice if the conditional operator (?:) would allow for both null-checking and having an implicit null value, simply by omitting the false-part of the expression, so that the same could be achieved using the following simplified code:\r\n\r\n**return a?.b ? foo(a.b);**\r\n\r\nThis could also be considered as an inverse null-coalesce operator (??), in that the statement\r\nreads \"_if a?.b is not null, return foo(a.b), otherwise just return null_\"\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/450237359","html_url":"https://github.com/dotnet/csharplang/issues/716#issuecomment-450237359","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/716","id":450237359,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDIzNzM1OQ==","user":{"login":"theunrepentantgeek","id":1272094,"node_id":"MDQ6VXNlcjEyNzIwOTQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1272094?v=4","gravatar_id":"","url":"https://api.github.com/users/theunrepentantgeek","html_url":"https://github.com/theunrepentantgeek","followers_url":"https://api.github.com/users/theunrepentantgeek/followers","following_url":"https://api.github.com/users/theunrepentantgeek/following{/other_user}","gists_url":"https://api.github.com/users/theunrepentantgeek/gists{/gist_id}","starred_url":"https://api.github.com/users/theunrepentantgeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theunrepentantgeek/subscriptions","organizations_url":"https://api.github.com/users/theunrepentantgeek/orgs","repos_url":"https://api.github.com/users/theunrepentantgeek/repos","events_url":"https://api.github.com/users/theunrepentantgeek/events{/privacy}","received_events_url":"https://api.github.com/users/theunrepentantgeek/received_events","type":"User","site_admin":false},"created_at":"2018-12-27T21:51:19Z","updated_at":"2018-12-27T21:51:19Z","author_association":"NONE","body":"Aside to @casperOne ... \r\n\r\n> No way, from the very beginning C# language designers made bool the only type that is supported in if conditional checks and the ternary operator.\r\n> One of the effects this had was that we always know that the expression evaluates to a bool.\r\n\r\nAny type can be used within an **if** or **while** if that type implements the **true** and **false** [operators](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/true-false-operators)!\r\n\r\nThis is very seldom used, but I have seen good use of it. I've also (ab)used it with almost criminal intent. 😉 \r\n"}}
{"actor":{"display_login":"theunrepentantgeek"}}