<commit_before>//
//  RawRepresentable.swift
//  SwiftFoundation
//
//  Created by <NAME> on 7/4/15.
//  Copyright © 2015 PureSwift. All rights reserved.
//

// MARK: - Convert Array of RawRepresentables

public extension RawRepresentable {
    
    /// Creates a collection of ```RawRepresentable``` from a collection of raw values. Returns ```nil``` if an element in the array had an invalid raw value.
    static func fromRawValues(rawValues: [RawValue]) -> [Self]? {
        
        var representables = [Self]()
        
        for element in rawValues {
            
            guard let rawRepresentable = self.init(rawValue: element) else {
                
                return nil
            }
            
            representables.append(rawRepresentable)
        }
        
        return representables
    }
}

public extension CollectionType where Self.Generator.Element: RawRepresentable {
    
    /// Converts a collection of ```RawRepresentable``` to its raw values.
    var rawValues: [Self.Generator.Element.RawValue] {
        
        typealias rawValueType = Self.Generator.Element.RawValue
        
        var rawValues = [rawValueType]()
        
        for rawRepresentable in self {
            
            rawValues.append(rawRepresentable.rawValue)
        }
        
        return rawValues
    }
}

// MARK: - SwiftFoundation Default Implementations

// MARK: CustomStringConvertible

public extension RawRepresentable {
    
    // Prints the raw value by default
    var description: String {
        
        return "\(rawValue)"
    }
}

// MARK: - Operator Overloading

// MARK: Equatable

public func == <T where T: RawRepresentable, T.RawValue: Equatable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue == rhs.rawValue
}

// MARK: Comparable

public func < <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue < rhs.rawValue
}

public func <= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue <= rhs.rawValue
}

public func >= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue >= rhs.rawValue<commit_msg>added default implementation for ~= in RawRepresentable<commit_after>//
//  RawRepresentable.swift
//  SwiftFoundation
//
//  Created by <NAME> on 7/4/15.
//  Copyright © 2015 PureSwift. All rights reserved.
//

// MARK: - Convert Array of RawRepresentables

public extension RawRepresentable {
    
    /// Creates a collection of ```RawRepresentable``` from a collection of raw values. Returns ```nil``` if an element in the array had an invalid raw value.
    static func fromRawValues(rawValues: [RawValue]) -> [Self]? {
        
        var representables = [Self]()
        
        for element in rawValues {
            
            guard let rawRepresentable = self.init(rawValue: element) else {
                
                return nil
            }
            
            representables.append(rawRepresentable)
        }
        
        return representables
    }
}

public extension CollectionType where Self.Generator.Element: RawRepresentable {
    
    /// Converts a collection of ```RawRepresentable``` to its raw values.
    var rawValues: [Self.Generator.Element.RawValue] {
        
        typealias rawValueType = Self.Generator.Element.RawValue
        
        var rawValues = [rawValueType]()
        
        for rawRepresentable in self {
            
            rawValues.append(rawRepresentable.rawValue)
        }
        
        return rawValues
    }
}

// MARK: - SwiftFoundation Default Implementations

// MARK: CustomStringConvertible

public extension RawRepresentable {
    
    // Prints the raw value by default
    var description: String {
        
        return "\(rawValue)"
    }
}

// MARK: - Operator Overloading

// MARK: Equatable

public func == <T where T: RawRepresentable, T.RawValue: Equatable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue == rhs.rawValue
}

public func ~= <T where T: RawRepresentable, T.RawValue: Equatable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue ~= rhs.rawValue
}

// MARK: Comparable

public func < <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue < rhs.rawValue
}

public func <= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue <= rhs.rawValue
}

public func >= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
    
    return lhs.rawValue >= rhs.rawValue
{'fraction_non_alphanumeric': 0.10197509660798626, 'fraction_numerical': 0.0034349506225848005, 'mean_word_length': 2.237665045170257, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 29, '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': '4712461', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1324, 'n_words': 395}