2019-07-31 17:33:48 -06:00
|
|
|
//
|
|
|
|
// TimelineSegment.swift
|
|
|
|
// Pachyderm
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 7/29/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2019-09-05 14:33:10 -04:00
|
|
|
public struct TimelineSegment<Type: Identifiable> where Type.ID == String {
|
2019-07-31 17:33:48 -06:00
|
|
|
private var ids: [String]
|
|
|
|
|
|
|
|
public init(objects: [Type]) {
|
|
|
|
self.ids = objects.map { $0.id }
|
|
|
|
}
|
|
|
|
|
|
|
|
public mutating func insertAtBeginning(ids: [String]) {
|
|
|
|
self.ids.insert(contentsOf: ids, at: 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
public mutating func insertAtBeginning(objects: [Type]) {
|
|
|
|
insertAtBeginning(ids: objects.map { $0.id })
|
|
|
|
}
|
|
|
|
|
|
|
|
public mutating func append(ids: [String]) {
|
|
|
|
self.ids.append(contentsOf: ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
public mutating func append(objects: [Type]) {
|
|
|
|
append(ids: objects.map { $0.id })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension TimelineSegment: RandomAccessCollection {
|
|
|
|
public typealias Index = Int
|
|
|
|
|
|
|
|
public subscript(index: Int) -> String {
|
|
|
|
return ids[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
public var startIndex: Int {
|
|
|
|
return ids.startIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
public var endIndex: Int {
|
|
|
|
return ids.endIndex
|
|
|
|
}
|
|
|
|
}
|