 //
 //
 
+/// Things that can go wrong when doing things to a `Tree`.
 public enum TreeError: Error {
     case indexOutOfBounds
     case branchOperationPerformedOnLeaf

    
    // MARK: - Cases
    
    /// Container node.
    indirect case branch(T, [Tree])
    
    /// Leaf node.
    case leaf(T)
    
    // MARK: - Instance Properties
    

        return try traverse(self, inserting: tree, through: path, at: index)
    }
    
    private func insert <A> (_ element: A, into elements: [A], at index: Int) throws -> [A] {
        
        guard let (left, right) = elements.split(at: index) else {
            throw TreeError.illFormedIndexPath
        }
        
        return left + [element] + right
    }
}

