<commit_before>extension Document: ExpressibleByArrayLiteral {
    /// Gets all top level values in this Document
    public var values: [Primitive] {
        ensureFullyCached()
        
        return cache.cachedDimensions.compactMap(self.readPrimitive)
    }
    
    public subscript(index: Int) -> Primitive {
        get {
            repeat {
                if cache.count > index {
                    return self[valueFor: cache[index].1]
                }
                
                _ = self.scanValue(startingAt: cache.lastScannedPosition, mode: .single)
            } while !self.fullyCached
            
            fatalError("Index \(index) out of range")
        }
        set {
            repeat {
                if cache.count > index {
                    self.write(newValue, forDimensions: cache[index].1, key: "\(index)")
                }
                
                _ = self.scanValue(startingAt: cache.lastScannedPosition, mode: .single)
            } while !self.fullyCached
            
            // TODO: Investigate other options than fatalError()
            fatalError("Index \(index) out of range")
        }
    }
    
    /// Appends a `Value` to this `Document` where this `Document` acts like an `Array`
    ///
    /// TODO: Analyze what should happen with `Dictionary`-like documents and this function
    ///
    /// - parameter value: The `Value` to append
    public mutating func append(_ value: Primitive) {
        let key = String(self.count)
        
        self.write(value, forKey: key)
    }
    
    public init(arrayLiteral elements: PrimitiveConvertible...) {
        self.init(elements: elements.compactMap { $0.makePrimitive() }.enumerated().map { ("\($0.offset)", $0.element) })
    }
    
    /// Converts an array of Primitives to a BSON ArrayDocument
    public init(array: [Primitive]) {
        self.init(isArray: true)
        
        for element in array {
            self.append(element)
        }
    }
}

extension Array where Element == Primitive {
    public init(valuesOf document: Document) {
        self = document.values
    }
}<commit_msg>Made arrayLiteral init use Document(array: )<commit_after>extension Document: ExpressibleByArrayLiteral {
    /// Gets all top level values in this Document
    public var values: [Primitive] {
        ensureFullyCached()
        
        return cache.cachedDimensions.compactMap(self.readPrimitive)
    }
    
    public subscript(index: Int) -> Primitive {
        get {
            repeat {
                if cache.count > index {
                    return self[valueFor: cache[index].1]
                }
                
                _ = self.scanValue(startingAt: cache.lastScannedPosition, mode: .single)
            } while !self.fullyCached
            
            fatalError("Index \(index) out of range")
        }
        set {
            repeat {
                if cache.count > index {
                    self.write(newValue, forDimensions: cache[index].1, key: "\(index)")
                }
                
                _ = self.scanValue(startingAt: cache.lastScannedPosition, mode: .single)
            } while !self.fullyCached
            
            // TODO: Investigate other options than fatalError()
            fatalError("Index \(index) out of range")
        }
    }
    
    /// Appends a `Value` to this `Document` where this `Document` acts like an `Array`
    ///
    /// TODO: Analyze what should happen with `Dictionary`-like documents and this function
    ///
    /// - parameter value: The `Value` to append
    public mutating func append(_ value: Primitive) {
        let key = String(self.count)
        
        self.write(value, forKey: key)
    }
    
    public init(arrayLiteral elements: PrimitiveConvertible...) {
        self.init(array: elements.compactMap { $0.makePrimitive() } )
    }
    
    /// Converts an array of Primitives to a BSON ArrayDocument
    public init(array: [Primitive]) {
        self.init(isArray: true)
        
        for element in array {
            self.append(element)
        }
    }
}

extension Array where Element == Primitive {
    public init(valuesOf document: Document) {
        self = document.values
    }
}
{'fraction_non_alphanumeric': 0.09922224840914447, 'fraction_numerical': 0.0018854584020740043, 'mean_word_length': 1.7170294494238156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6528816', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1109, 'n_words': 302}