<commit_before>define(
  'ephox.boulder.combine.ResultCombine',

  [
    'ephox.katamari.api.Arr',
    'ephox.katamari.api.Merger',
    'ephox.katamari.api.Result'
  ],

  function (Arr, Merger, Result) {
    var consolidateObj = function (objects, base) {
      // This used to be done in a functional way with folding, but
      // I was worried about its performance (because this is called a lot)

      // Note, we should use katamari's Results.partition (or other) when this is
      // migrated.
      var passed = [ base ];
      var failed = [ ];
      var unsuccessful = false;
      Arr.each(objects, function (obj) {
        obj.fold(function (errs) {
          // errs can be empty ,but this should still fail
          unsuccessful = true;
          failed = failed.concat(errs);
        }, function (obj) {
          passed.push(obj);
        });
      });

      if (unsuccessful) return Result.error(failed);
      else if (passed.length === 0) return Result.value({ });
      else return Result.value(
        Merger.deepMerge.apply(undefined, passed)
      );
    };

    var consolidateArr = function (objects) {
      var passed = [ ];
      var failed = [ ];
      var unsuccessful = false;
      Arr.each(objects, function (obj) {
        obj.fold(function (errs) {
          // errs can be empty ,but this should still fail
          unsuccessful = true;
          failed = failed.concat(errs);
        }, function (arr) {
          passed.push(arr);
        });
      });

      // This used to (also) be done in a functional way with folding, but
      // I was worried about its performance (because this is called a lot)
      if (unsuccessful) return Result.error(failed);
      else return Result.value(passed);
    };

    return {
      consolidateObj: consolidateObj,
      consolidateArr: consolidateArr
    };
  }
);<commit_msg>VAN-75: leveraging partitions in Results<commit_after>define(
  'ephox.boulder.combine.ResultCombine',

  [
    'ephox.katamari.api.Arr',
    'ephox.katamari.api.Fun',
    'ephox.katamari.api.Merger',
    'ephox.katamari.api.Result',
    'ephox.katamari.api.Results'
  ],

  function (Arr, Fun, Merger, Result, Results) {
    var mergeValues = function (values, base) {
      return Result.value(
        Merger.deepMerge.apply(undefined, [ base ].concat(values))
      );
    };

    var mergeErrors = function (errors) {
      return Fun.compose(Result.error, Arr.flatten)(errors);
    };

    var consolidateObj = function (objects, base) {
      var partitions = Results.partition(objects);
      return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base);
    };

    var consolidateArr = function (objects) {
      var partitions = Results.partition(objects);
      return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : Result.value(partitions.values);
    };

    return {
      consolidateObj: consolidateObj,
      consolidateArr: consolidateArr
    };
  }
);
{'fraction_non_alphanumeric': 0.11911911911911911, 'fraction_numerical': 0.001668335001668335, 'mean_word_length': 2.4699074074074074, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3743380', 'n_tokens_mistral': 911, 'n_tokens_neox': 897, 'n_words': 228}