<commit_before>//
//  Int+Extensions.swift
//  SwiftWisdom
//
//  Created by <NAME> on 1/19/16.
//  Copyright © 2016 Intrepid. All rights reserved.
//

import Foundation

extension Integer {
    public var ip_isEven: Bool {
        return (self % 2) == 0
    }
    
    public var ip_isOdd: Bool {
        return !ip_isEven
    }
}

extension Integer where Self : _Strideable & Comparable, Self.Stride : SignedInteger  {
    public func ip_times(_ closure: @escaping Block) {
        precondition(self >= 0)
        (0..<self).forEach { _ in closure() }
    }
}

extension Integer {
    public func ip_toMagnitudeString(_ decimalPlaces: Int = 1) -> String {
        
        guard self > 999 else { return "\(self)" }
        
        let units = ["K", "M", "B", "T", "Q"]
        
        let value = Double(self.toIntMax())
        
        var magnitude: Int = Int(log10(value) / 3.0) // the order of magnitude of our value in thousands
        
        // divide value by 1000^magnitude to get hundreds value, then round to desired decimal places
        var roundedHundredsValue = (value / pow(1000.0, Double(magnitude))).round(toDecimalPlaces: decimalPlaces)
        
        // if rounding brings our display value over 1000, divide by 1000 and then bump the magnitude
        if roundedHundredsValue >= 1000 {
            roundedHundredsValue /= 1000.0
            magnitude += 1
        }
        
        // if our number exceeds our current magnitude system return the scientific notation
        let magnitudeSuffix = units[ip_safe: magnitude - 1] ?? "E\(magnitude * 3)"
        
        let formatter = NumberFormatter.decimalFormatter
        guard let valueFormatted = formatter.string(from: NSNumber(value: roundedHundredsValue)) else {
            return "\(roundedHundredsValue)\(magnitudeSuffix)"
        }
        
        return "\(valueFormatted)\(magnitudeSuffix)"
    }
}

extension NumberFormatter {
    fileprivate static var decimalFormatter: NumberFormatter {
        let decimalFormatter = NumberFormatter()
        decimalFormatter.numberStyle = .decimal
        decimalFormatter.minimumFractionDigits = 0
        return decimalFormatter
    }
}
<commit_msg>remove reference to Block which is defined in another module<commit_after>//
//  Int+Extensions.swift
//  SwiftWisdom
//
//  Created by <NAME> on 1/19/16.
//  Copyright © 2016 Intrepid. All rights reserved.
//

import Foundation

extension Integer {
    public var ip_isEven: Bool {
        return (self % 2) == 0
    }
    
    public var ip_isOdd: Bool {
        return !ip_isEven
    }
}

extension Integer where Self : _Strideable & Comparable, Self.Stride : SignedInteger  {
    public func ip_times(_ closure: @escaping (Void) -> Void) {
        precondition(self >= 0)
        (0..<self).forEach { _ in closure() }
    }
}

extension Integer {
    public func ip_toMagnitudeString(_ decimalPlaces: Int = 1) -> String {
        
        guard self > 999 else { return "\(self)" }
        
        let units = ["K", "M", "B", "T", "Q"]
        
        let value = Double(self.toIntMax())
        
        var magnitude: Int = Int(log10(value) / 3.0) // the order of magnitude of our value in thousands
        
        // divide value by 1000^magnitude to get hundreds value, then round to desired decimal places
        var roundedHundredsValue = (value / pow(1000.0, Double(magnitude))).round(toDecimalPlaces: decimalPlaces)
        
        // if rounding brings our display value over 1000, divide by 1000 and then bump the magnitude
        if roundedHundredsValue >= 1000 {
            roundedHundredsValue /= 1000.0
            magnitude += 1
        }
        
        // if our number exceeds our current magnitude system return the scientific notation
        let magnitudeSuffix = units[ip_safe: magnitude - 1] ?? "E\(magnitude * 3)"
        
        let formatter = NumberFormatter.decimalFormatter
        guard let valueFormatted = formatter.string(from: NSNumber(value: roundedHundredsValue)) else {
            return "\(roundedHundredsValue)\(magnitudeSuffix)"
        }
        
        return "\(valueFormatted)\(magnitudeSuffix)"
    }
}

extension NumberFormatter {
    fileprivate static var decimalFormatter: NumberFormatter {
        let decimalFormatter = NumberFormatter()
        decimalFormatter.numberStyle = .decimal
        decimalFormatter.minimumFractionDigits = 0
        return decimalFormatter
    }
}

{'fraction_non_alphanumeric': 0.09341155234657039, 'fraction_numerical': 0.023014440433212997, 'mean_word_length': 2.3456603773584908, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '979495', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1210, 'n_words': 376}