Created
December 12, 2016 05:45
Revisions
-
lukesutton created this gist
Dec 12, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ struct File {} struct Landscape { let parents: FileList let children: FileList } struct FileList { fileprivate let all: Array<File> fileprivate let before: ArraySlice<File> fileprivate let after: ArraySlice<File> var previous: FileList { guard !before.isEmpty else { return self } return shift(by: before.count - 1) } var next: FileList { guard !after.isEmpty else { return self } return shift(by: before.count + 1) } var current: File? { return before.last } var isEmpty: Bool { return all.isEmpty } fileprivate func shift(by prefixLength: Int) -> FileList { return FileList( all: all, before: all.prefix(prefixLength), after: all.suffix(all.count - prefixLength) ) } } extension FileList { fileprivate init(_ elements: File...) { self.all = elements self.before = elements.prefix(1) self.after = elements.suffix(elements.count - 1) } }