<commit_before>//  Copyright © 2015 <NAME>. All rights reserved.

import Foundation

public class ValueTransformer<A, B>: NSValueTransformer {

    // MARK: - Value Transformation Block Types

    /// The type of a block used to perform a forwad transform.
    public typealias ForwardTransformer = (value: A?) -> B?
    /// The type of a block used to perform a reverse transform.
    public typealias ReverseTransformer = (value: B?) -> A?


    // MARK: - Value Transformers

    private let forwardTransformer: ForwardTransformer
    private let reverseTransformer: ReverseTransformer?


    // MARK: - Creating a New Value Transformer

    /// Create a new value transformer using the given transformation block _forwardBlock_.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    public class func forwardTransformer(forwardTransformer: ForwardTransformer) -> ValueTransformer<A, B> {
        return ValueTransformer<A, B>(forwardTransformer: forwardTransformer, reverseTransformer: nil)
    }

    /// Create a new value transformer using the given transformation block _forwardBlock_.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    /// - parameter reverseTransformer: A block used to perform a reverse value transformation, that is
    /// from value type `B?` to `A?`.
    public class func reversibleForwardTransformer(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer) -> ValueTransformer<A, B> {
        return ReversibleValueTransformer<A, B>(forwardTransformer: forwardTransformer, reverseTransformer: reverseTransformer)
    }

    /// Initialize a newly allocated value transformer with the given forward and reverse
    /// transformation blocks.
    ///
    /// Note: You probably want to use on of the class functions instead to get a new instance;
    /// namely `ValueTransformer.forwardTransformer()` or
    /// `ValueTransformer.reversibleForwardTransformer(reverseTransformer:)`.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    /// - parameter reverseTransformer: A block used to perform a reverse value transformation, that is
    /// from value type `B?` to `A?`. This is an optional parameter.
    public required init(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer?) {
        self.forwardTransformer = forwardTransformer
        self.reverseTransformer = reverseTransformer
    }


    // MARK: - NSValueTransformer

    public override class func transformedValueClass() -> AnyClass {
        // We’d want to return `B.self` but I don’t know how to do that yet…
        return NSObject.self
    }

    public override class func allowsReverseTransformation() -> Bool {
        return false
    }

    /// Perform the forward value transform.
    public func transformedValue(value: A?) -> B? {
        return self.forwardTransformer(value: value)
    }

}


// MARK: - ReversibleValueTransformer Class

/// Any ValueTransformer supporting reverse transformation. Necessary because
/// `allowsReverseTransformation` is a class function.
public class ReversibleValueTransformer<A, B>: ValueTransformer<A, B> {

    public required init(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer?) {
        assert(reverseTransformer != nil, "AlimentoCore.ReversibleValueTransformer requires the given _reverseBlock_ to have some value (i.e. it must not be `nil`).")
        super.init(forwardTransformer: forwardTransformer, reverseTransformer: reverseTransformer)
    }

    public override class func allowsReverseTransformation() -> Bool {
        return true
    }

    public func reverseTransformedValue(value: B?) -> A? {
        return self.reverseTransformer!(value: value)
    }
    
}<commit_msg>Add comment on explicit unwrap<commit_after>//  Copyright © 2015 <NAME>. All rights reserved.

import Foundation

public class ValueTransformer<A, B>: NSValueTransformer {

    // MARK: - Value Transformation Block Types

    /// The type of a block used to perform a forwad transform.
    public typealias ForwardTransformer = (value: A?) -> B?
    /// The type of a block used to perform a reverse transform.
    public typealias ReverseTransformer = (value: B?) -> A?


    // MARK: - Value Transformers

    private let forwardTransformer: ForwardTransformer
    private let reverseTransformer: ReverseTransformer?


    // MARK: - Creating a New Value Transformer

    /// Create a new value transformer using the given transformation block _forwardBlock_.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    public class func forwardTransformer(forwardTransformer: ForwardTransformer) -> ValueTransformer<A, B> {
        return ValueTransformer<A, B>(forwardTransformer: forwardTransformer, reverseTransformer: nil)
    }

    /// Create a new value transformer using the given transformation block _forwardBlock_.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    /// - parameter reverseTransformer: A block used to perform a reverse value transformation, that is
    /// from value type `B?` to `A?`.
    public class func reversibleForwardTransformer(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer) -> ValueTransformer<A, B> {
        return ReversibleValueTransformer<A, B>(forwardTransformer: forwardTransformer, reverseTransformer: reverseTransformer)
    }

    /// Initialize a newly allocated value transformer with the given forward and reverse
    /// transformation blocks.
    ///
    /// Note: You probably want to use on of the class functions instead to get a new instance;
    /// namely `ValueTransformer.forwardTransformer()` or
    /// `ValueTransformer.reversibleForwardTransformer(reverseTransformer:)`.
    ///
    /// - parameter forwardTransformer: A block used to perform a forward value transformation, that is
    /// from value type `A?` to `B?`.
    /// - parameter reverseTransformer: A block used to perform a reverse value transformation, that is
    /// from value type `B?` to `A?`. This is an optional parameter.
    public required init(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer?) {
        self.forwardTransformer = forwardTransformer
        self.reverseTransformer = reverseTransformer
    }


    // MARK: - NSValueTransformer

    public override class func transformedValueClass() -> AnyClass {
        // We’d want to return `B.self` but I don’t know how to do that yet…
        return NSObject.self
    }

    public override class func allowsReverseTransformation() -> Bool {
        return false
    }

    /// Perform the forward value transform.
    public func transformedValue(value: A?) -> B? {
        return self.forwardTransformer(value: value)
    }

}


// MARK: - ReversibleValueTransformer Class

/// Any ValueTransformer supporting reverse transformation. Necessary because
/// `allowsReverseTransformation` is a class function.
public class ReversibleValueTransformer<A, B>: ValueTransformer<A, B> {

    public required init(forwardTransformer: ForwardTransformer, reverseTransformer: ReverseTransformer?) {
        assert(reverseTransformer != nil, "AlimentoCore.ReversibleValueTransformer requires the given _reverseBlock_ to have some value (i.e. it must not be `nil`).")
        super.init(forwardTransformer: forwardTransformer, reverseTransformer: reverseTransformer)
    }

    public override class func allowsReverseTransformation() -> Bool {
        return true
    }

    public func reverseTransformedValue(value: B?) -> A? {
        // The explicit unwrap should be fine here as we assert during initialization that the
        // `reverseTransformer` exists and we’re immutable.
        return self.reverseTransformer!(value: value)
    }
    
}
{'fraction_non_alphanumeric': 0.08600583090379009, 'fraction_numerical': 0.0009718172983479105, 'mean_word_length': 3.36763925729443, 'pattern_counts': {'":': 0, '<': 19, '<?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': '3204627', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2000, 'n_words': 773}