{"id":13308,"date":"2016-01-17T16:27:18","date_gmt":"2016-01-17T21:27:18","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13308"},"modified":"2016-01-20T19:15:31","modified_gmt":"2016-01-21T00:15:31","slug":"swift-golf","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/01\/17\/swift-golf\/","title":{"rendered":"Swift Golf"},"content":{"rendered":"<p><a href=\"https:\/\/www.cocoanetics.com\/2015\/12\/swift-golf\/\">Cocoanetics<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.cocoanetics.com\/2015\/12\/swift-golf\/\">\n<p>We learned several new ways to pick out a specific element from a collection. I found the discussion exhilarating and uniquely instructive. In particular combining for + where and for + case let were new to me. I am sure that I will soon find more uses for these.<\/p>\n<p>Playing Code Golf in Swift is not about brevity, but mostly about beauty, elegance and code readability. Because of this I ended up with an approach that reads like plain english to me: &ldquo;from the cell&rsquo;s content view&rsquo;s subviews, get the first element of type UISwitch&rdquo;. Anybody can understand that.<\/p>\n<\/blockquote>\n<p>I would lean towards a combination of Variant 6 and Variant 3. It probably doesn&rsquo;t matter much for this particular case, but a reusable generic extension should not <code>flatMap<\/code> the entire collection just to find one element.<\/p>\n<p>Update (2016-01-20): <a href=\"https:\/\/twitter.com\/arekholko\/status\/688852835518312448\">Arkadiusz Holko<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/arekholko\/status\/688852835518312448\"><p>V. 6 can be even smarter by inferring generic from return type.<\/p><\/blockquote>\n<p>This is cool but seems risky and potentially confusing to me.<\/p>","protected":false},"excerpt":{"rendered":"<p>Cocoanetics: We learned several new ways to pick out a specific element from a collection. I found the discussion exhilarating and uniquely instructive. In particular combining for + where and for + case let were new to me. I am sure that I will soon find more uses for these. Playing Code Golf in Swift [&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":[69,31,71,901],"class_list":["post-13308","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-ios","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13308","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=13308"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13308\/revisions"}],"predecessor-version":[{"id":13324,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13308\/revisions\/13324"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}