{"id":9433,"date":"2014-09-02T14:28:56","date_gmt":"2014-09-02T18:28:56","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=9433"},"modified":"2014-09-02T14:28:56","modified_gmt":"2014-09-02T18:28:56","slug":"swift-default-protocol-implementations","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/09\/02\/swift-default-protocol-implementations\/","title":{"rendered":"Swift Default Protocol Implementations"},"content":{"rendered":"<p><a href=\"http:\/\/nshipster.com\/swift-default-protocol-implementations\/\">Mattt Thompson<\/a>:<\/p><blockquote cite=\"http:\/\/nshipster.com\/swift-default-protocol-implementations\/\"><p>All of this highlights a significant tension between methods and functions in Swift.<\/p><p>The Object-Oriented paradigm is based around the concept of objects that encapsulate both state and behavior. However, in Swift, it&rsquo;s simply impossible to implement certain generic functions as methods on the <code>struct<\/code> or <code>class<\/code> itself.<\/p><p>[&#8230;]<\/p><p>Because of the constraint on the element of the sequence generator being <code>Equatable<\/code>, this cannot be declared on a generic container, without thereby requiring elements in that collection to conform to <code>Equatable<\/code>.<\/p><p>Relegating behavior like <code>contains<\/code>, <code>advance<\/code>, or <code>partition<\/code> to top-level functions does a  disservice to the standard library. Not only does it hide functionality from method autocompletion, but it fragments the API across a Object-Oriented and Functional paradigms.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mattt Thompson:All of this highlights a significant tension between methods and functions in Swift.The Object-Oriented paradigm is based around the concept of objects that encapsulate both state and behavior. However, in Swift, it&rsquo;s simply impossible to implement certain generic functions as methods on the struct or class itself.[&#8230;]Because of the constraint on the element of [&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":[46,71,901],"class_list":["post-9433","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9433","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=9433"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9433\/revisions"}],"predecessor-version":[{"id":9434,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/9433\/revisions\/9434"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=9433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=9433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=9433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}