<commit_before>{EventEmitter: $EventEmitter} = require 'events'

#----------------------------------------------------------------------

$_ = require 'underscore'

#=====================================================================

# TODO: move these helpers in a dedicated module.

$done = {}

# Similar to `$_.each()` but can be interrupted by returning the
# special value `done` provided as the forth argument.
$each = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    # Array-like object.
    i = 0
    while i < n and (iterator.call ctx, col[i], "#{i}", col, $done) isnt $done
      ++i
  else
    for key of col
      break if (iterator.call ctx, col[key], key, $done) is $done

  # For performance.
  undefined

$makeFunction = (val) -> -> val

# Similar to `$_.map()` for array and `$_.mapValues()` for objects.
#
# Note: can  be interrupted by returning the special value `done`
# provided as the forth argument.
$map = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    result = []
    # Array-like object.
    i = 0
    while i < n
      value = iterator.call ctx, col[i], "#{i}", col, $done
      break if value is $done
      result.push value
      ++i
  else
    result = {}
    for key of col
      value = iterator.call ctx, col[key], key, $done
      break if value is $done
      result.push value

  # The new collection is returned.
  result

# Similar to `$map()` but change the current collection.
#
# Note: can  be interrupted by returning the special value `done`
# provided as the forth argument.
$mapInPlace = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    # Array-like object.
    i = 0
    while i < n
      value = iterator.call ctx, col[i], "#{i}", col, $done
      break if value is $done
      col[i] = value
      ++i
  else
    for key of col
      value = iterator.call ctx, col[key], key, $done
      break if value is $done
      col[key] = value

  # The collection is returned.
  col

#=====================================================================

class $MappedCollection2 extends $EventEmitter

  # The dispatch function is called whenever a new item has to be
  # processed and returns the name of the rule to use.
  #
  # To change the way it is dispatched, just override this it.
  dispatch: ->
    (@genval and (@genval.rule ? @genval.type)) ? 'unknown'

  # This function is called when an item has been dispatched to a
  # missing rule.
  #
  # The default behavior is to throw an error but you may instead
  # choose to create a rule:
  #
  #     collection.missingRule = collection.rule
  missingRule: (name) ->
    throw new Error "undefined rule “#{name}”"

  # This option makes `set()` create missing rules when necessary
  # instead of failing.
  #
  # TODO: should be replaced by a callback for flexibility.
  createMissingRules: false

  constructor: ->
    # Items are stored here indexed by key.
    #
    # The prototype of this object is set to `null` to avoid pollution
    # from enumerable properties of `Object.prototype` and the
    # performance hit of  `hasOwnProperty o`.
    @_byKey = Object.create null

    # Hooks are stored here indexed by moment.
    @_hooks = {
      beforeDispatch: []
      beforeUpdate: []
      beforeSave: []
      afterRule: []
    }

    # Rules are stored here indexed by name.
    #
    # The prototype of this object is set to `null` to avoid pollution
    # from enumerable properties of `Object.prototype` and to be able
    # to use the `name of @_rules` syntax.
    @_rules = Object.create null

  # Register a hook to run at a given point.
  #
  # A hook receives as parameter an event object with the following
  # properties:
  # - `preventDefault()`: prevents the next default action from
  #   happening;
  # - `stopPropagation()`: prevents other hooks from being run.
  #<commit_msg>Minor cleanup.<commit_after>{EventEmitter: $EventEmitter} = require 'events'

#----------------------------------------------------------------------

$_ = require 'underscore'

#=====================================================================

# TODO: move these helpers in a dedicated module.

$done = {}

# Similar to `$_.each()` but can be interrupted by returning the
# special value `done` provided as the forth argument.
$each = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    # Array-like object.
    i = 0
    while i < n and (iterator.call ctx, col[i], "#{i}", col, $done) isnt $done
      ++i
  else
    for key of col
      break if (iterator.call ctx, col[key], key, $done) is $done

  # For performance.
  undefined

$makeFunction = (val) -> -> val

# Similar to `$_.map()` for array and `$_.mapValues()` for objects.
#
# Note: can  be interrupted by returning the special value `done`
# provided as the forth argument.
$map = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    result = []
    # Array-like object.
    i = 0
    while i < n
      value = iterator.call ctx, col[i], "#{i}", col, $done
      break if value is $done
      result.push value
      ++i
  else
    result = {}
    for key of col
      value = iterator.call ctx, col[key], key, $done
      break if value is $done
      result.push value

  # The new collection is returned.
  result

# Similar to `$map()` but change the current collection.
#
# Note: can  be interrupted by returning the special value `done`
# provided as the forth argument.
$mapInPlace = (col, iterator, ctx) ->
  # The default context is inherited.
  ctx ?= this

  if (n = col.length)?
    # Array-like object.
    i = 0
    while i < n
      value = iterator.call ctx, col[i], "#{i}", col, $done
      break if value is $done
      col[i] = value
      ++i
  else
    for key of col
      value = iterator.call ctx, col[key], key, $done
      break if value is $done
      col[key] = value

  # The collection is returned.
  col

#=====================================================================

class $MappedCollection2 extends $EventEmitter

  # The dispatch function is called whenever a new item has to be
  # processed and returns the name of the rule to use.
  #
  # To change the way it is dispatched, just override this it.
  dispatch: ->
    (@genval and (@genval.rule ? @genval.type)) ? 'unknown'

  # This function is called when an item has been dispatched to a
  # missing rule.
  #
  # The default behavior is to throw an error but you may instead
  # choose to create a rule:
  #
  #     collection.missingRule = collection.rule
  missingRule: (name) ->
    throw new Error "undefined rule “#{name}”"

  constructor: ->
    # Items are stored here indexed by key.
    #
    # The prototype of this object is set to `null` to avoid pollution
    # from enumerable properties of `Object.prototype` and the
    # performance hit of  `hasOwnProperty o`.
    @_byKey = Object.create null

    # Hooks are stored here indexed by moment.
    @_hooks = {
      beforeDispatch: []
      beforeUpdate: []
      beforeSave: []
      afterRule: []
    }

    # Rules are stored here indexed by name.
    #
    # The prototype of this object is set to `null` to avoid pollution
    # from enumerable properties of `Object.prototype` and to be able
    # to use the `name of @_rules` syntax.
    @_rules = Object.create null

  # Register a hook to run at a given point.
  #
  # A hook receives as parameter an event object with the following
  # properties:
  # - `preventDefault()`: prevents the next default action from
  #   happening;
  # - `stopPropagation()`: prevents other hooks from being run.
  #
{'fraction_non_alphanumeric': 0.15130054081895442, 'fraction_numerical': 0.0010301313417460727, 'mean_word_length': 2.6311360448807855, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '4012346', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2201, 'n_words': 938}