Last active
August 29, 2015 14:25
-
-
Save kazmasaurus/aab5362f3aece0e4d6a8 to your computer and use it in GitHub Desktop.
Potential solution to Brent's problem
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
protocol Feed { | |
var url: String {get} | |
} | |
protocol Folder { | |
typealias FeedType | |
var feeds: [FeedType] {get} | |
func addFeeds(feedsToAdd: [FeedType]) | |
} | |
class LocalFeed: Feed { | |
var url: String | |
init(url: String) { | |
self.url = url | |
} | |
} | |
extension LocalFeed: Equatable { } | |
func ==(lhs: LocalFeed, rhs: LocalFeed) -> Bool { | |
return lhs.url == rhs.url | |
} | |
class LocalFolder<F: Feed where F: Equatable>: Folder { | |
typealias FeedType = F | |
var feeds = [FeedType]() | |
func addFeeds(feedsToAdd: [FeedType]) { | |
for oneFeed in feedsToAdd { | |
if !feeds.contains(oneFeed) { | |
feeds += [oneFeed] | |
} | |
} | |
} | |
} | |
let folder = LocalFolder<LocalFeed>() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure if this satisfies all your requirements, but it seems like making
Folder
generic through an associated type might get you to where you want to be.