<commit_before>//
//  NSCoder+Tuka.swift
//  Tuka
//
//  Created by <NAME> on 2017/03/31.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public protocol CodingKeyRepresentable {
    var codingKey: String { get }
}

extension String: CodingKeyRepresentable {
    public var codingKey: String {
        return self
    }
}

extension RawRepresentable where RawValue == String, Self: CodingKeyRepresentable {
    public var codingKey: String {
        return rawValue
    }
}

extension NSCoder {
    public struct TukaExtension {
        let coder: NSCoder
    }

    public var tuka: TukaExtension {
        return TukaExtension(coder: self)
    }
}

extension NSCoder.TukaExtension {
    public func encode(_ value: Any?, forKey key: CodingKeyRepresentable) {
        coder.encode(value, forKey: key.codingKey)
    }
}

extension NSCoder.TukaExtension {
    public func decodeObject<Object>(of type: Object.Type, forKey key: CodingKeyRepresentable) -> Object? where Object: NSObject, Object: NSCoding {
        return coder.decodeObject(of: Object.self, forKey: key.codingKey)
    }

    public func decodeObject<Object>(of type: Object.Type, forKey key: CodingKeyRepresentable) -> Object? where Object: ReferenceConvertible, Object.ReferenceType: NSObject, Object.ReferenceType: NSCoding {
        return coder.decodeObject(of: Object.ReferenceType.self, forKey: key.codingKey) as? Object
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: ExpressibleByIntegerLiteral {
        return coder.decodeObject(of: NSNumber.self, forKey: key.codingKey) as? Value
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: ExpressibleByStringLiteral {
        return coder.decodeObject(of: NSString.self, forKey: key.codingKey) as? Value
    }
}

extension NSCoder.TukaExtension {
    public func encode<Value>(_ value: Value, forKey key: CodingKeyRepresentable) where Value: RawRepresentable {
        encode(value.rawValue, forKey: key)
    }
}

extension NSCoder.TukaExtension {
    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: RawRepresentable, Value.RawValue: ExpressibleByIntegerLiteral {
        guard let rawValue = decodeValue(of: Value.RawValue.self, forKey: key) else {
            return nil
        }
        return Value(rawValue: rawValue)
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: RawRepresentable, Value.RawValue: ExpressibleByStringLiteral {
        guard let rawValue = decodeValue(of: Value.RawValue.self, forKey: key) else {
            return nil
        }
        return Value(rawValue: rawValue)
    }
}<commit_msg>Support `ExpressibleByBooleanLiteral`<commit_after>//
//  NSCoder+Tuka.swift
//  Tuka
//
//  Created by <NAME> on 2017/03/31.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public protocol CodingKeyRepresentable {
    var codingKey: String { get }
}

extension String: CodingKeyRepresentable {
    public var codingKey: String {
        return self
    }
}

extension RawRepresentable where RawValue == String, Self: CodingKeyRepresentable {
    public var codingKey: String {
        return rawValue
    }
}

extension NSCoder {
    public struct TukaExtension {
        let coder: NSCoder
    }

    public var tuka: TukaExtension {
        return TukaExtension(coder: self)
    }
}

extension NSCoder.TukaExtension {
    public func encode(_ value: Any?, forKey key: CodingKeyRepresentable) {
        coder.encode(value, forKey: key.codingKey)
    }
}

extension NSCoder.TukaExtension {
    public func decodeObject<Object>(of type: Object.Type, forKey key: CodingKeyRepresentable) -> Object? where Object: NSObject, Object: NSCoding {
        return coder.decodeObject(of: Object.self, forKey: key.codingKey)
    }

    public func decodeObject<Object>(of type: Object.Type, forKey key: CodingKeyRepresentable) -> Object? where Object: ReferenceConvertible, Object.ReferenceType: NSObject, Object.ReferenceType: NSCoding {
        return coder.decodeObject(of: Object.ReferenceType.self, forKey: key.codingKey) as? Object
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: ExpressibleByBooleanLiteral {
        return coder.decodeObject(of: NSNumber.self, forKey: key.codingKey) as? Value
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: ExpressibleByIntegerLiteral {
        return coder.decodeObject(of: NSNumber.self, forKey: key.codingKey) as? Value
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: ExpressibleByStringLiteral {
        return coder.decodeObject(of: NSString.self, forKey: key.codingKey) as? Value
    }
}

extension NSCoder.TukaExtension {
    public func encode<Value>(_ value: Value, forKey key: CodingKeyRepresentable) where Value: RawRepresentable {
        encode(value.rawValue, forKey: key)
    }
}

extension NSCoder.TukaExtension {
    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: RawRepresentable, Value.RawValue: ExpressibleByBooleanLiteral {
        guard let rawValue = decodeValue(of: Value.RawValue.self, forKey: key) else {
            return nil
        }
        return Value(rawValue: rawValue)
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: RawRepresentable, Value.RawValue: ExpressibleByIntegerLiteral {
        guard let rawValue = decodeValue(of: Value.RawValue.self, forKey: key) else {
            return nil
        }
        return Value(rawValue: rawValue)
    }

    public func decodeValue<Value>(of type: Value.Type, forKey key: CodingKeyRepresentable) -> Value? where Value: RawRepresentable, Value.RawValue: ExpressibleByStringLiteral {
        guard let rawValue = decodeValue(of: Value.RawValue.self, forKey: key) else {
            return nil
        }
        return Value(rawValue: rawValue)
    }
}
{'fraction_non_alphanumeric': 0.0918204964990452, 'fraction_numerical': 0.0038192234245703373, 'mean_word_length': 3.6043956043956045, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, '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': '1521458', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1810, 'n_words': 503}