<commit_before>//
//  ObservableArray.swift
//  SwiftPlusPlus
//
//  Created by <NAME> on 7/9/16.
//  Copyright © 2016 Drewag LLC. All rights reserved.
//

public final class ObservableArray<Element> {
    public typealias DidChange = ([Element]) -> ()
    public typealias DidInsert = (Element, at: Int) -> ()
    public typealias DidRemove = (Element, at: Int) -> ()
    public typealias DidRemoveAll = (oldValues: [Element]) -> ()
    public typealias ObservationHandlers = (changed: DidChange?, insert: DidInsert?, remove: DidRemove?, removeAll: DidRemoveAll?)

    private var observers: [(observer: WeakWrapper, handlers: [ObservationHandlers])] = []
    private var onHasObserversChanged: ((Bool) -> ())?

    public private(set) var values: [Element]

    public init(_ values: [Element], onHasObserversChanged: ((Bool) -> ())? = nil) {
        self.values = values
        self.onHasObserversChanged = onHasObserversChanged
    }

    public func add(
        observer observer: AnyObject,
        onDidChange: DidChange? = nil,
        onDidInsert: DidInsert? = nil,
        onDidRemove: DidRemove? = nil,
        onDidRemoveAll: DidRemoveAll? = nil
        )
    {
        guard onDidChange != nil || onDidInsert != nil || onDidRemove != nil || onDidRemoveAll != nil else {
            return
        }

        let handlers: ObservationHandlers = (changed: onDidChange, insert: onDidInsert, remove: onDidRemove, removeAll: onDidRemoveAll)
        if let index = self.index(ofObserver: observer) {
            self.observers[index].handlers.append(handlers)
        }
        else {
            let oldCount = self.observers.count
            self.observers.append((observer: WeakWrapper(observer), handlers: [handlers]))
            if oldCount == 0 {
                self.onHasObserversChanged?(true)
            }
        }
    }

    public func remove(observer observer: AnyObject) {
        if let index = self.index(ofObserver: observer) {
            self.observers.removeAtIndex(index)
            if self.observers.count == 0 {<commit_msg>[IC] Removed change callback from observable array as it wasn't being called<commit_after>//
//  ObservableArray.swift
//  SwiftPlusPlus
//
//  Created by <NAME> on 7/9/16.
//  Copyright © 2016 Drewag LLC. All rights reserved.
//

public final class ObservableArray<Element> {
    public typealias DidInsert = (Element, at: Int) -> ()
    public typealias DidRemove = (Element, at: Int) -> ()
    public typealias DidRemoveAll = (oldValues: [Element]) -> ()
    public typealias ObservationHandlers = (insert: DidInsert?, remove: DidRemove?, removeAll: DidRemoveAll?)

    private var observers: [(observer: WeakWrapper, handlers: [ObservationHandlers])] = []
    private var onHasObserversChanged: ((Bool) -> ())?

    public private(set) var values: [Element]

    public init(_ values: [Element], onHasObserversChanged: ((Bool) -> ())? = nil) {
        self.values = values
        self.onHasObserversChanged = onHasObserversChanged
    }

    public func add(
        observer observer: AnyObject,
        onDidInsert: DidInsert? = nil,
        onDidRemove: DidRemove? = nil,
        onDidRemoveAll: DidRemoveAll? = nil
        )
    {
        guard onDidInsert != nil || onDidRemove != nil || onDidRemoveAll != nil else {
            return
        }

        let handlers: ObservationHandlers = (insert: onDidInsert, remove: onDidRemove, removeAll: onDidRemoveAll)
        if let index = self.index(ofObserver: observer) {
            self.observers[index].handlers.append(handlers)
        }
        else {
            let oldCount = self.observers.count
            self.observers.append((observer: WeakWrapper(observer), handlers: [handlers]))
            if oldCount == 0 {
                self.onHasObserversChanged?(true)
            }
        }
    }

    public func remove(observer observer: AnyObject) {
        if let index = self.index(ofObserver: observer) {
            self.observers.removeAtIndex(index)
            if self.observers.count == 0 {
{'fraction_non_alphanumeric': 0.1134558093346574, 'fraction_numerical': 0.004965243296921549, 'mean_word_length': 2.6560798548094375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, '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': '4313868', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1124, 'n_words': 300}