Last active
August 29, 2015 14:25
-
-
Save roop/5bb4713110093e96adb1 to your computer and use it in GitHub Desktop.
Brent's Feeds and Folders problem. See: http://roopc.net/posts/2015/brents-feeds-and-folders/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Feed: Equatable { | |
var url: String { get } | |
} | |
func ==<T: Feed>(lhs: T, rhs: T) -> Bool { | |
return (lhs.url == rhs.url) | |
} | |
protocol Folder { | |
typealias FeedType: Feed | |
var feeds: [FeedType] { get } | |
func addFeeds(feedsToAdd: [FeedType]) | |
} | |
struct LocalFeed: Feed { | |
var url: String | |
init(url: String) { | |
self.url = url | |
} | |
} | |
class LocalFolder: Folder { | |
var feeds: [LocalFeed] = [] | |
func addFeeds(feedsToAdd: [LocalFeed]) { | |
for oneFeed in feedsToAdd { | |
if !feeds.contains(oneFeed) { | |
feeds += [oneFeed] | |
} | |
} | |
} | |
} | |
let folder = LocalFolder() | |
folder.addFeeds([ LocalFeed(url: "1"), LocalFeed(url: "2") ]) | |
folder.addFeeds([ LocalFeed(url: "2"), LocalFeed(url: "3") ]) | |
print(folder.feeds.count) // 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment