<commit_before>var contracts = { };

contracts.map = function(f,arr) {
  var dest = [ ];
  for (var i = 0; i < arr.length; i++) {
    dest.push(f(arr[i]));
  }
  return dest;
};

contracts.zipWith = function(f,arr1,arr2) {
  var dest = [ ];
  for (var i = 0; i < arr1.length; i++) {
    dest.push(f(arr1[i],arr2[i]));
  }
  return dest;
};

contracts.blame = function(guilty,expected,received,message,loc) {
  var guiltyMsg = typeof(guilty) == "string" 
                    ? guilty : guilty.value;
  var msg = guiltyMsg + " violated the contract at " + loc + "; expected " + 
             expected + " but received " + received + "; " + message;
  var err = new Error(msg);
  err.guilty = msg;
  err.blamed = guiltyMsg;
  err.expected = expected;
  err.received = received;
  err.guardLoc = loc;
  try { console.log(err); } catch(_) { };
  throw err;
}

// The type of a contract combinator is: name -> args ... -> contract
//
// name is a human-readable name for the contract.  args .. are constructor-
// specified arguments and contract is the resulting contract.
 

contracts.flat = function(name) {
  return function(pred) {
    return {
      pred: function(val) { return pred(val); },
      server: function(s,loc) {
        return function(val) {
          if (pred(val)) { 
            return val; 
            }
          else { 
            contracts.blame(s,name,val,"does not satisfy the predicate",loc);
         }
        };
      },
      client: function(s,loc) {
        return function(val) { return val; };
      }
    };
  };
};


contracts.unsizedArray = function(name) {
  return function(elt) {
    return {
      pred: function(val) {
        return val instanceof Array;
        for (var i = 0; i < val.length; i++) {
          if (!(elt.flat(val[i]))) { return false; }
        }
        return true;
      },
      server: function(s,loc) {
        return function(val) {
          if (val instanceof Array) {
            return contracts.map(elt.server(s,loc),val);
          }
          else {
            contracts.blame(s, name, val, "not an array",loc);
          }
        };
      },
      client: function(s,loc) {
        return function(val) {
          if (val instanceof Array) {
            return contracts.map(elt.client(s,loc),val);
          }
          else {
            return val;
          }
        }
      }
    };
  };
};

contracts.fixedArray = function(name) {
  return function() {
    var elts = arguments;
    return {
      pred: function(val) {
        if  (!(val instanceof Array && val.length == elts.length)) {
          return false;
        }
        for (var i = 0; i < val.length; i++) {
          if (!elts[i].flat(val[i])) { return false; }
        }
        return true;<commit_msg>typo, fixedArray and flat predicate is called flat<commit_after>var contracts = { };

contracts.map = function(f,arr) {
  var dest = [ ];
  for (var i = 0; i < arr.length; i++) {
    dest.push(f(arr[i]));
  }
  return dest;
};

contracts.zipWith = function(f,arr1,arr2) {
  var dest = [ ];
  for (var i = 0; i < arr1.length; i++) {
    dest.push(f(arr1[i],arr2[i]));
  }
  return dest;
};

contracts.blame = function(guilty,expected,received,message,loc) {
  var guiltyMsg = typeof(guilty) == "string" 
                    ? guilty : guilty.value;
  var msg = guiltyMsg + " violated the contract at " + loc + "; expected " + 
             expected + " but received " + received + "; " + message;
  var err = new Error(msg);
  err.guilty = msg;
  err.blamed = guiltyMsg;
  err.expected = expected;
  err.received = received;
  err.guardLoc = loc;
  try { console.log(err); } catch(_) { };
  throw err;
}

// The type of a contract combinator is: name -> args ... -> contract
//
// name is a human-readable name for the contract.  args .. are constructor-
// specified arguments and contract is the resulting contract.
 

contracts.flat = function(name) {
  return function(pred) {
    return {
      flat: function(val) { return pred(val); },
      server: function(s,loc) {
        return function(val) {
          if (flat(val)) { 
            return val; 
            }
          else { 
            contracts.blame(s,name,val,"does not satisfy the predicate",loc);
         }
        };
      },
      client: function(s,loc) {
        return function(val) { return val; };
      }
    };
  };
};


contracts.unsizedArray = function(name) {
  return function(elt) {
    return {
      flat: function(val) {
        return val instanceof Array;
        for (var i = 0; i < val.length; i++) {
          if (!(elt.flat(val[i]))) { return false; }
        }
        return true;
      },
      server: function(s,loc) {
        return function(val) {
          if (val instanceof Array) {
            return contracts.map(elt.server(s,loc),val);
          }
          else {
            contracts.blame(s, name, val, "not an array",loc);
          }
        };
      },
      client: function(s,loc) {
        return function(val) {
          if (val instanceof Array) {
            return contracts.map(elt.client(s,loc),val);
          }
          else {
            return val;
          }
        }
      }
    };
  };
};

contracts.fixedArray = function(name) {
  return function() {
    var elts = arguments;
    return {
      flat: function(val) {
        if  (!(val instanceof Array && val.length == elts.length)) {
          return false;
        }
        for (var i = 0; i < val.length; i++) {
          if (!elts[i].flat(val[i])) { return false; }
        }
        return true;
{'fraction_non_alphanumeric': 0.14450658488183293, 'fraction_numerical': 0.0032473389861086056, 'mean_word_length': 1.9209694415173868, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '3170595', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1727, 'n_words': 434}