{"id":22322,"date":"2018-07-31T16:26:37","date_gmt":"2018-07-31T20:26:37","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=22322"},"modified":"2018-07-31T16:27:17","modified_gmt":"2018-07-31T20:27:17","slug":"the-swift-compiler-can-reason-about-never","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/07\/31\/the-swift-compiler-can-reason-about-never\/","title":{"rendered":"The Swift Compiler Can Reason About &ldquo;Never&rdquo;"},"content":{"rendered":"<p><a href=\"https:\/\/nshipster.com\/never\/\">Mattt Thompson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/nshipster.com\/never\/\">\n<p>By specifying <code>Never<\/code> as the result&rsquo;s <code>Error<\/code> type, we&rsquo;re using the type system to signal that failure is not an option. What&rsquo;s really cool about this is that Swift is smart enough to know that you don&rsquo;t need to handle <code>.failure<\/code> for the <code>switch<\/code> statement to be exhaustive:<\/p>\n<pre>alwaysSucceeds { (result) in\n    switch result {\n    case .success(let string):\n        print(string)\n    }\n}<\/pre>\n<p>You can see this effect played out to its logical extreme in the implementation conforming <code>Never<\/code> to <code>Comparable<\/code>:<\/p>\n<pre>extension Never: Comparable {\n  public static func &lt; (lhs: Never, rhs: Never) -&gt; Bool {\n    switch (lhs, rhs) {}\n  }\n}\n<\/pre>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mattt Thompson: By specifying Never as the result&rsquo;s Error type, we&rsquo;re using the type system to signal that failure is not an option. What&rsquo;s really cool about this is that Swift is smart enough to know that you don&rsquo;t need to handle .failure for the switch statement to be exhaustive: alwaysSucceeds { (result) in switch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-07-31T20:27:19Z","apple_news_api_id":"18faf8bb-5441-4907-82ef-3412ae4247f9","apple_news_api_modified_at":"2018-07-31T20:27:20Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AGPr4u1RBSQeC7zQSrkJH-Q","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[255,46,71,901],"class_list":["post-22322","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-compiler","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=22322"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22322\/revisions"}],"predecessor-version":[{"id":22328,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/22322\/revisions\/22328"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=22322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=22322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=22322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}