<commit_before>var Rx = require('rx');


var slice = Array.prototype.slice;


function create(map) {
  var observers = [];
  
  var actionStart = new Rx.Subject();
  var actionEnd = new Rx.Subject();
  
  var action = function (value) {
    if (typeof map !== 'undefined') {
      if (typeof map === 'function') {
        value = map(value);
      } else {
        value = map;
      }
    } 
    
    actionStart.onNext(value);
    var os = observers.slice(0);
    for (var i = 0, len = os.length; i < len; i++) {
        os[i].onNext(value);
    }
    actionEnd.onNext();
    
    return value;
  };
  
  for (var key in Rx.Observable.prototype) {
    action[key] = Rx.Subject.prototype[key];
  }
  

  
  Rx.Observable.call(action, function (observer) {
      observers.push(observer);
      return {
        dispose: function () {
          var index = observers.indexOf(observer);
          if (index !== -1) {
            observers.splice(index, 1);
          }
        }
      };
  });
  
  action.hasObservers  = function () {
    return observers.length > 0 || actionStart.hasObservers() || actionEnd.hasObservers();
  };
  
  action.waitFor = function (observables) {
    observables = slice.call(arguments);
    return actionStart
      .flatMap(function (value) {
        return Rx.Observable.combineLatest(
          observables.map(function (observable) {
            observable =  observable.takeUntil(actionEnd).publish();
            observable.connect();
            return observable;
          }),
          function () {
            return value;
          }
        );
      });
  };
  <commit_msg>waitFor can now takes a selector function<commit_after>var Rx = require('rx');

var slice = Array.prototype.slice;

function create(map) {
  var observers = [];
  
  var actionStart = new Rx.Subject();
  var actionEnd = new Rx.Subject();
  
  var action = function (value) {
    if (typeof map !== 'undefined') {
      if (typeof map === 'function') {
        value = map(value);
      } else {
        value = map;
      }
    } 
    
    actionStart.onNext(value);
    var os = observers.slice(0);
    for (var i = 0, len = os.length; i < len; i++) {
        os[i].onNext(value);
    }
    actionEnd.onNext();
    
    return value;
  };
  
  for (var key in Rx.Observable.prototype) {
    action[key] = Rx.Subject.prototype[key];
  }
  

  
  Rx.Observable.call(action, function (observer) {
      observers.push(observer);
      return {
        dispose: function () {
          var index = observers.indexOf(observer);
          if (index !== -1) {
            observers.splice(index, 1);
          }
        }
      };
  });
  
  action.hasObservers  = function () {
    return observers.length > 0 || actionStart.hasObservers() || actionEnd.hasObservers();
  };
  
  action.waitFor = function (observables, selector) {
    if (!Array.isArray(observables)) {
      observables = [observables];
    }
    return actionStart
      .flatMap(function (value) {
        return Rx.Observable.combineLatest(
          observables.map(function (observable) {
            observable =  observable.takeUntil(actionEnd).publish();
            observable.connect();
            return observable;
          }),
          function (observablesValues) {
            if (selector) {
              observablesValues = slice.call(arguments);
              observablesValues.unshift(value);
              return selector.apply(void(0), observablesValues);
            } else {
              return value;
            }
          }
        );
      });
  };
  
{'fraction_non_alphanumeric': 0.13176338659938325, 'fraction_numerical': 0.0030838239416876925, 'mean_word_length': 1.9659185369908563, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6221541', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1061, 'n_words': 223}