<commit_before>//
//  CombinedChangeable.swift
//  SwiftRebound
//
//  Created by <NAME> on 12/07/2016.
//
//

import Foundation

///
/// Changeable implementation that works by combined many changeable objects into one
///
internal class CombinedChangeable : Changeable {
    /// The chageables that are combined in this one
    private var _combined: [Changeable];
    
    init(changeables: [Changeable]) {
        var flatChangeables = [Changeable]();
        
        // Flatten out the list so that we don't create nested combined changeables
        for changeable in changeables {
            let alsoCombined = changeable as? CombinedChangeable;
            if let alsoCombined = alsoCombined {
                flatChangeables.appendContentsOf(alsoCombined._combined);
            }
        }
        
        _combined = flatChangeables;
    }

    ///
    /// Calls a function any time this value is marked as changed
    ///
    func whenChanged(target: Notifiable) -> Lifetime {
        var lifetimes = [Lifetime]();
        
        // Combine the changeables and generate a lifetime for each one
        for changeable in _combined {
            let lifetime = changeable.whenChanged(target);
            lifetimes.append(lifetime);
        }
        
        // Result is a combined lifetime
        return CombinedLifetime(lifetimes: lifetimes);
    }
    
    ///
    /// Adds a new changeable to the changeable items being managed by this object
    ///
    func addChangeable(newChangeable: Changeable) {
        _combined.append(newChangeable);
    }
    
    ///
    /// Finds if this represents the same changeable as the specified combined changeable
    ///
    func isSameAs(compareTo: CombinedChangeable) -> Bool {
        // Lengths must be the same
        if _combined.count != compareTo._combined.count {
            return false;
        }
        
        // Changeables must be the same
        for index in 0..<_combined.count {
            if _combined[index] !== compareTo._combined[index] {<commit_msg>This needs to be public so we can return it from the BindingContext functions<commit_after>//
//  CombinedChangeable.swift
//  SwiftRebound
//
//  Created by <NAME> on 12/07/2016.
//
//

import Foundation

///
/// Changeable implementation that works by combined many changeable objects into one
///
public class CombinedChangeable : Changeable {
    /// The chageables that are combined in this one
    private var _combined: [Changeable];
    
    public init(changeables: [Changeable]) {
        var flatChangeables = [Changeable]();
        
        // Flatten out the list so that we don't create nested combined changeables
        for changeable in changeables {
            let alsoCombined = changeable as? CombinedChangeable;
            if let alsoCombined = alsoCombined {
                flatChangeables.appendContentsOf(alsoCombined._combined);
            }
        }
        
        _combined = flatChangeables;
    }

    ///
    /// Calls a function any time this value is marked as changed
    ///
    public func whenChanged(target: Notifiable) -> Lifetime {
        var lifetimes = [Lifetime]();
        
        // Combine the changeables and generate a lifetime for each one
        for changeable in _combined {
            let lifetime = changeable.whenChanged(target);
            lifetimes.append(lifetime);
        }
        
        // Result is a combined lifetime
        return CombinedLifetime(lifetimes: lifetimes);
    }
    
    ///
    /// Adds a new changeable to the changeable items being managed by this object
    ///
    public func addChangeable(newChangeable: Changeable) {
        _combined.append(newChangeable);
    }
    
    ///
    /// Finds if this represents the same changeable as the specified combined changeable
    ///
    public func isSameAs(compareTo: CombinedChangeable) -> Bool {
        // Lengths must be the same
        if _combined.count != compareTo._combined.count {
            return false;
        }
        
        // Changeables must be the same
        for index in 0..<_combined.count {
            if _combined[index] !== compareTo._combined[index] {
{'fraction_non_alphanumeric': 0.08249400479616308, 'fraction_numerical': 0.004316546762589928, 'mean_word_length': 2.0445255474452555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7240011', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1070, 'n_words': 355}