{"id":11779,"date":"2015-07-22T11:34:55","date_gmt":"2015-07-22T15:34:55","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11779"},"modified":"2015-07-22T11:34:55","modified_gmt":"2015-07-22T15:34:55","slug":"every-swift-value-type-should-be-equatable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/07\/22\/every-swift-value-type-should-be-equatable\/","title":{"rendered":"Every Swift Value Type Should Be Equatable"},"content":{"rendered":"<p><a href=\"http:\/\/www.andrewcbancroft.com\/2015\/07\/01\/every-swift-value-type-should-be-equatable\/\">Andrew Bancroft<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.andrewcbancroft.com\/2015\/07\/01\/every-swift-value-type-should-be-equatable\/\">\n<p>To be truly equal, the <code>==<\/code> operator not only needs to be implemented, but it needs to be implemented in such a way that it <em>behaves<\/em> as we&rsquo;d expect when doing our comparisons. During the talk, Doug mentioned three important properties of equality that need to hold for our Value Types:<\/p>\n<ol>\n<li>The comparison must be <strong>reflexive<\/strong><\/li>\n<li>The comparison must be <strong>symmetric<\/strong><\/li>\n<li>The comparison must be <strong>transitive<\/strong><\/li>\n<\/ol>\n<p>[&#8230;]<\/p>\n<p>If Reference Types are involved with your Value Type implementation, things could get a little more complicated.  &ldquo;Complicated&rdquo; probably isn&rsquo;t the right word&#8230; but you do have to <em>think<\/em> a little more about your Type&rsquo;s equality semantics.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Andrew Bancroft: To be truly equal, the == operator not only needs to be implemented, but it needs to be implemented in such a way that it behaves as we&rsquo;d expect when doing our comparisons. During the talk, Doug mentioned three important properties of equality that need to hold for our Value Types: The comparison [&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":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","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":[71,901],"class_list":["post-11779","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11779","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=11779"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11779\/revisions"}],"predecessor-version":[{"id":11780,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11779\/revisions\/11780"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}