<commit_before>/*
 * pat
 * https://github.com/mikko/pat
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

"use strict";

var _ = require("lodash");

function last(arr) {
  return arr.slice(-1)[0];
}

function initial(arr) {
  return arr.slice(0, -1);
}

function toArray(args) {
  return Array.prototype.slice.call(args);
}

function match(patterns, args) {
  var matches = patterns.filter(function(pattern) {
    return pattern.args.length === args.length && _.every(_.zip(pattern.args, args), function(zipped) {
      var patt = zipped[0], arg = zipped[1];
      return _.isFunction(patt) ? patt(arg) : _.isEqual(patt, arg);
    })
  });
  return matches[0];
}

function pat(f) {
  var patterns = [];

  if(!f) {
    f = function() {};
  }

  var wrapper = function() {
    var matchedPattern = match(patterns, toArray(arguments));

    if(matchedPattern) {
      return matchedPattern.clbk.apply(this, arguments);
    } else {
      return f.apply(this, arguments);
    }
  }

  wrapper.caseof = function() {
    var args = toArray(arguments);
    var clbk = last(args);
    args = initial(args);
    patterns.push(Object.freeze({args: args, clbk: clbk}));
    return wrapper;
  };
  <commit_msg>Remove unused helpers, use lodash<commit_after>/*
 * pat
 * https://github.com/mikko/pat
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

"use strict";

var _ = require("lodash");

function match(patterns, args) {
  var matches = patterns.filter(function(pattern) {
    return pattern.args.length === args.length && _.every(_.zip(pattern.args, args), function(zipped) {
      var patt = zipped[0], arg = zipped[1];
      return _.isFunction(patt) ? patt(arg) : _.isEqual(patt, arg);
    })
  });
  return matches[0];
}

function pat(f) {
  var patterns = [];

  if(!f) {
    f = function() {};
  }

  var wrapper = function() {
    var matchedPattern = match(patterns, _.toArray(arguments));

    if(matchedPattern) {
      return matchedPattern.clbk.apply(this, arguments);
    } else {
      return f.apply(this, arguments);
    }
  }

  wrapper.caseof = function() {
    var clbk = _.last(arguments);
    var args = _.initial(arguments);
    patterns.push(Object.freeze({args: args, clbk: clbk}));
    return wrapper;
  };
  
{'fraction_non_alphanumeric': 0.16234051913770348, 'fraction_numerical': 0.007919049714034315, 'mean_word_length': 3.2267657992565058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7263366', 'n_tokens_mistral': 791, 'n_tokens_neox': 766, 'n_words': 171}