<commit_before>import { MonteError } from './MonteError';
import { flattenDeep } from '../external/lodash';
import { isFunc } from '../tools/is';

export class InstanceGroup {
  constructor(instances, proxyMethodSet, ...additionalMethodsToProxy) {
    this._instances = [];
    this._methodsToProxy = proxyMethodSet.concat(flattenDeep(...additionalMethodsToProxy));

    this._methodsToProxy.forEach((m) => this.addProxyMethod(m));
    instances.forEach((instance) => this.addInstance(instance));
  }

  addProxyMethod(methodName) {
    this[methodName] = this.invokeProxyMethod.bind(this, methodName);
  }

  removeProxyMethod(methodName) {
    const index = this._methodsToProxy.indexOf(methodName);

    if (index > -1) { this._methodsToProxy.splice(index, 1); }
  }

  addInstance(instance) {
    this._instances.push(instance);
  }

  removeChart(instance) {
    const index = this._instances.indexOf(instance);

    if (index > -1) { this._instances.splice(index, 1); }
  }

  invokeProxyMethod(methodName, ...args) {
    this._instances.forEach((instance) => {
      if (instance && instance[methodName] && isFunc(instance[methodName])) {<commit_msg>Prevent adding undefined and null instances to groups<commit_after>import { MonteError } from './MonteError';
import { flattenDeep } from '../external/lodash';
import { isFunc } from '../tools/is';

export class InstanceGroup {
  constructor(instances, proxyMethodSet, ...additionalMethodsToProxy) {
    this._instances = [];
    this._methodsToProxy = proxyMethodSet.concat(flattenDeep(...additionalMethodsToProxy));

    this._methodsToProxy.forEach((m) => this.addProxyMethod(m));
    instances.forEach((instance) => this.addInstance(instance));
  }

  addProxyMethod(methodName) {
    this[methodName] = this.invokeProxyMethod.bind(this, methodName);
  }

  removeProxyMethod(methodName) {
    const index = this._methodsToProxy.indexOf(methodName);

    if (index > -1) { this._methodsToProxy.splice(index, 1); }
  }

  addInstance(instance) {
    if (instance) {
      this._instances.push(instance);
    }
  }

  removeChart(instance) {
    const index = this._instances.indexOf(instance);

    if (index > -1) { this._instances.splice(index, 1); }
  }

  invokeProxyMethod(methodName, ...args) {
    this._instances.forEach((instance) => {
      if (instance && instance[methodName] && isFunc(instance[methodName])) {
{'fraction_non_alphanumeric': 0.1452560873215785, 'fraction_numerical': 0.0033585222502099076, 'mean_word_length': 4.248898678414097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3802427', 'n_tokens_mistral': 737, 'n_tokens_neox': 714, 'n_words': 121}