Skip to content

Instantly share code, notes, and snippets.

@mortenbekditlevsen
Created August 8, 2018 12:33
Show Gist options
  • Save mortenbekditlevsen/fa74e0cd7737e53bda05d22fcf9b3b42 to your computer and use it in GitHub Desktop.
Save mortenbekditlevsen/fa74e0cd7737e53bda05d22fcf9b3b42 to your computer and use it in GitHub Desktop.
// So from the Objc.io talk, we learn about a way of representing filesystem paths that can point to either files or directories.
// Internally, these are represented as an array of path elements. Let's do that too:
public struct Path<Element> {
private var components: [String]
fileprivate func append<T>(_ args: String ...) -> Path<T> {
return Path<T>(components + args)
}
fileprivate init(_ components: [String]) {
self.components = components
}
var rendered: String {
return components.joined(separator: "/")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment