<commit_before>//
//  <NAME> L
//
//       ()
//       /\
//  ()--'  '--()
//    `.    .'
//     / .. \
//    ()'  '()
//
//


import Foundation


// MARK: - Types

public typealias MarshalDictionary = [String: AnyObject]


// MARK: - Dictionary Extensions

extension Dictionary: MarshaledObject {
    public subscript(key: KeyType) -> Any? {
        guard let aKey = key as? Key else { return nil }
        
        return self[aKey]
    }
}

extension NSDictionary: MarshaledObject {
    public func anyForKey(key: KeyType) throws -> Any {
        let value:Any
        if key.dynamicType.keyTypeSeparator == "." {
            // `valueForKeyPath` is more efficient. Use it if possible.
            guard let v = self.valueForKeyPath(key.stringValue) else {
                throw Error.KeyNotFound(key: key)
            }
            value = v
        }
        else {
            let pathComponents = key.split()
            var accumulator: Any = self

            for component in pathComponents {
                if let componentData = accumulator as? MarshaledObject, v = componentData[component] {
                    accumulator = v
                    continue
                }
                throw Error.KeyNotFound(key: key.stringValue)
            }
            value = accumulator
        }

        if let _ = value as? NSNull {
            throw Error.NullValue(key: key)
        }

        return value
    }<commit_msg>make NSDictionary conform to ValueType<commit_after>//
//  <NAME> L
//
//       ()
//       /\
//  ()--'  '--()
//    `.    .'
//     / .. \
//    ()'  '()
//
//


import Foundation


// MARK: - Types

public typealias MarshalDictionary = [String: AnyObject]


// MARK: - Dictionary Extensions

extension Dictionary: MarshaledObject {
    public subscript(key: KeyType) -> Any? {
        guard let aKey = key as? Key else { return nil }
        
        return self[aKey]
    }
}

extension NSDictionary: ValueType { }

extension NSDictionary: MarshaledObject {
    public func anyForKey(key: KeyType) throws -> Any {
        let value:Any
        if key.dynamicType.keyTypeSeparator == "." {
            // `valueForKeyPath` is more efficient. Use it if possible.
            guard let v = self.valueForKeyPath(key.stringValue) else {
                throw Error.KeyNotFound(key: key)
            }
            value = v
        }
        else {
            let pathComponents = key.split()
            var accumulator: Any = self

            for component in pathComponents {
                if let componentData = accumulator as? MarshaledObject, v = componentData[component] {
                    accumulator = v
                    continue
                }
                throw Error.KeyNotFound(key: key.stringValue)
            }
            value = accumulator
        }

        if let _ = value as? NSNull {
            throw Error.NullValue(key: key)
        }

        return value
    }
{'fraction_non_alphanumeric': 0.10571040108769544, 'fraction_numerical': 0.0, 'mean_word_length': 1.4710327455919396, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6791288', 'n_tokens_mistral': 831, 'n_tokens_neox': 789, 'n_words': 211}