<commit_before>import Foundation
import ReactiveSwift
#if !COCOAPODS
import Moya
#endif

/// Extension for processing raw NSData generated by network access.
extension SignalProducerProtocol where Value == Response, Error == MoyaError {

    /// Filters out responses that don't fall within the given range, generating errors when others are encountered.
    public func filter(statusCodes: ClosedRange<Int>) -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filter(statusCodes: statusCodes) }
        }
    }

    public func filter(statusCode: Int) -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filter(statusCode: statusCode) }
        }
    }

    public func filterSuccessfulStatusCodes() -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filterSuccessfulStatusCodes() }
        }
    }

    public func filterSuccessfulStatusAndRedirectCodes() -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filterSuccessfulStatusAndRedirectCodes() }
        }
    }

    /// Maps data received from the signal into an Image. If the conversion fails, the signal errors.
    public func mapImage() -> SignalProducer<Image, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapImage() }
        }
    }

    /// Maps data received from the signal into a JSON object. If the conversion fails, the signal errors.
    public func mapJSON(failsOnEmptyData: Bool = true) -> SignalProducer<Any, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapJSON(failsOnEmptyData: failsOnEmptyData) }
        }
    }

    /// Maps received data at key path into a String. If the conversion fails, the signal errors.
    public func mapString(atKeyPath keyPath: String? = nil) -> SignalProducer<String, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapString(atKeyPath: keyPath) }
        }
    }

    /// Maps received data at key path into a Decodable object. If the conversion fails, the signal errors.
    public func map<D: Decodable>(_ type: D.Type, atKeyPath keyPath: String? = nil, using decoder: JSONDecoder = JSONDecoder(), failsOnEmptyData: Bool = true) -> SignalProducer<D, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.map(type, atKeyPath: keyPath, using: decoder, failsOnEmptyData: failsOnEmptyData) }
        }
    }
}

/// Maps throwable to SignalProducer.
private func unwrapThrowable<T>(throwable: () throws -> T) -> SignalProducer<T, MoyaError> {
    do {
        return SignalProducer(value: try throwable())
    } catch {
        if let error = error as? MoyaError {
            return SignalProducer(error: error)
        } else {
            // The cast above should never fail, but just in case.
            return SignalProducer(error: MoyaError.underlying(error as NSError, nil))
        }
    }
}

<commit_msg>fix the 2 SwiftLint warnings<commit_after>import Foundation
import ReactiveSwift
#if !COCOAPODS
import Moya
#endif

/// Extension for processing raw NSData generated by network access.
extension SignalProducerProtocol where Value == Response, Error == MoyaError {

    /// Filters out responses that don't fall within the given range, generating errors when others are encountered.
    public func filter(statusCodes: ClosedRange<Int>) -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filter(statusCodes: statusCodes) }
        }
    }

    public func filter(statusCode: Int) -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filter(statusCode: statusCode) }
        }
    }

    public func filterSuccessfulStatusCodes() -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filterSuccessfulStatusCodes() }
        }
    }

    public func filterSuccessfulStatusAndRedirectCodes() -> SignalProducer<Value, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.filterSuccessfulStatusAndRedirectCodes() }
        }
    }

    /// Maps data received from the signal into an Image. If the conversion fails, the signal errors.
    public func mapImage() -> SignalProducer<Image, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapImage() }
        }
    }

    /// Maps data received from the signal into a JSON object. If the conversion fails, the signal errors.
    public func mapJSON(failsOnEmptyData: Bool = true) -> SignalProducer<Any, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapJSON(failsOnEmptyData: failsOnEmptyData) }
        }
    }

    /// Maps received data at key path into a String. If the conversion fails, the signal errors.
    public func mapString(atKeyPath keyPath: String? = nil) -> SignalProducer<String, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.mapString(atKeyPath: keyPath) }
        }
    }

    /// Maps received data at key path into a Decodable object. If the conversion fails, the signal errors.
    public func map<D: Decodable>(_ type: D.Type, atKeyPath keyPath: String? = nil, using decoder: JSONDecoder = JSONDecoder(), failsOnEmptyData: Bool = true) -> SignalProducer<D, MoyaError> {
        return producer.flatMap(.latest) { response in
            unwrapThrowable { try response.map(type, atKeyPath: keyPath, using: decoder, failsOnEmptyData: failsOnEmptyData) }
        }
    }
}

/// Maps throwable to SignalProducer.
private func unwrapThrowable<T>(throwable: () throws -> T) -> SignalProducer<T, MoyaError> {
    do {
        return SignalProducer(value: try throwable())
    } catch {
        if let error = error as? MoyaError {
            return SignalProducer(error: error)
        } else {
            // The cast above should never fail, but just in case.
            return SignalProducer(error: MoyaError.underlying(error as NSError, nil))
        }
    }
}
{'fraction_non_alphanumeric': 0.08807118081737295, 'fraction_numerical': 0.00015080681646810435, 'mean_word_length': 2.968880909634949, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '4036839', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1772, 'n_words': 558}