<commit_before>import Foundation
import Moya
import Mapper

public extension Response {

    public func map<T: Mappable>(to type: T.Type) throws -> T {
        guard let jsonDictionary = try mapJSON() as? NSDictionary else {
            throw MoyaError.jsonMapping(self)
        }

        do {
            return try T(map: Mapper(JSON: jsonDictionary))
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }
    
    public func map<T: Mappable>(to type: T.Type, keyPath: String?) throws -> T {
        guard let keyPath = keyPath else { return try map(to: type) }
        
        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectDictionary = jsonDictionary.value(forKeyPath:keyPath) as? NSDictionary else {
                throw MoyaError.jsonMapping(self)
        }

        do {
            return try T(map: Mapper(JSON: objectDictionary))
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }
    
    public func map<T: Mappable>(to type: [T].Type) throws -> [T] {
        guard let jsonArray = try mapJSON() as? [NSDictionary] else {
            throw MoyaError.jsonMapping(self)
        }

        do {
            return try jsonArray.map { try T(map: Mapper(JSON: $0)) }
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }

    public func compactMap<T: Mappable>(to type: [T].Type) throws -> [T] {
        guard let jsonArray = try mapJSON() as? [NSDictionary] else {
            throw MoyaError.jsonMapping(self)
        }

        return jsonArray.compactMap { try? T(map: Mapper(JSON: $0)) }
    }
    
    public func map<T: Mappable>(to type: [T].Type, keyPath: String?) throws -> [T] {
        guard let keyPath = keyPath else { return try map(to: type) }
        
        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectArray = jsonDictionary.value(forKeyPath:keyPath) as? [NSDictionary] else {
                throw MoyaError.jsonMapping(self)
        }

        do {
            return try objectArray.map { try T(map: Mapper(JSON: $0)) }
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }

    public func compactMap<T: Mappable>(to type: [T].Type, keyPath: String?) throws -> [T] {
        guard let keyPath = keyPath else { return try compactMap(to: type) }

        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectArray = jsonDictionary.value(forKeyPath:keyPath) as? [NSDictionary] else {
                throw MoyaError.jsonMapping(self)
        }

        return objectArray.compactMap { try? T(map: Mapper(JSON: $0)) }
    }
}<commit_msg>Remove redundant "public" modifier from extension<commit_after>import Foundation
import Moya
import Mapper

public extension Response {

    func map<T: Mappable>(to type: T.Type) throws -> T {
        guard let jsonDictionary = try mapJSON() as? NSDictionary else {
            throw MoyaError.jsonMapping(self)
        }

        do {
            return try T(map: Mapper(JSON: jsonDictionary))
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }
    
    func map<T: Mappable>(to type: T.Type, keyPath: String?) throws -> T {
        guard let keyPath = keyPath else { return try map(to: type) }
        
        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectDictionary = jsonDictionary.value(forKeyPath:keyPath) as? NSDictionary else {
                throw MoyaError.jsonMapping(self)
        }

        do {
            return try T(map: Mapper(JSON: objectDictionary))
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }
    
    func map<T: Mappable>(to type: [T].Type) throws -> [T] {
        guard let jsonArray = try mapJSON() as? [NSDictionary] else {
            throw MoyaError.jsonMapping(self)
        }

        do {
            return try jsonArray.map { try T(map: Mapper(JSON: $0)) }
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }

    func compactMap<T: Mappable>(to type: [T].Type) throws -> [T] {
        guard let jsonArray = try mapJSON() as? [NSDictionary] else {
            throw MoyaError.jsonMapping(self)
        }

        return jsonArray.compactMap { try? T(map: Mapper(JSON: $0)) }
    }
    
    func map<T: Mappable>(to type: [T].Type, keyPath: String?) throws -> [T] {
        guard let keyPath = keyPath else { return try map(to: type) }
        
        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectArray = jsonDictionary.value(forKeyPath:keyPath) as? [NSDictionary] else {
                throw MoyaError.jsonMapping(self)
        }

        do {
            return try objectArray.map { try T(map: Mapper(JSON: $0)) }
        } catch {
            throw MoyaError.underlying(error, self)
        }
    }

    func compactMap<T: Mappable>(to type: [T].Type, keyPath: String?) throws -> [T] {
        guard let keyPath = keyPath else { return try compactMap(to: type) }

        guard let jsonDictionary = try mapJSON() as? NSDictionary,
            let objectArray = jsonDictionary.value(forKeyPath:keyPath) as? [NSDictionary] else {
                throw MoyaError.jsonMapping(self)
        }

        return objectArray.compactMap { try? T(map: Mapper(JSON: $0)) }
    }
}
{'fraction_non_alphanumeric': 0.10534124629080119, 'fraction_numerical': 0.001483679525222552, 'mean_word_length': 2.1245654692931635, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '249392', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1580, 'n_words': 441}