Created
December 17, 2015 22:09
-
-
Save oisdk/b2f98ee66378dc81e4db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Node { | |
let name: String | |
init(_ name: String) { | |
self.name = name | |
} | |
} | |
extension RangeReplaceableCollectionType where Generator.Element == Node { | |
mutating func node(name: String) -> Node { | |
if let firstMatch = self.lazy.filter({ n in n.name == name }).first { | |
return firstMatch | |
} | |
let newNode = Node(name) | |
self.append(newNode) | |
return newNode | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment