<commit_before>
module Dense; class << self

  def get(o, path)

    pa = Dense::Path.new(path)
    r = pa.gather(o).inject([]) { |a, e| a << e[2][e[3]] if e.first; a }

    pa.single? ? r.first : r
  end

  def fetch(o, path, default=::KeyError, &block)

    pa = Dense::Path.new(path)
    r = pa.gather(o).partition(&:first)

    if r[0].empty?

      return pa.narrow(
        r[1].collect { |m| call_default_block(o, path, block, m) }
      ) if block

      return pa.narrow(
        r[1].collect { |m| default }
      ) if default != KeyError

      fail key_error(path, r[1].first)
    end

    pa.narrow(r[0].collect { |e| e[2][e[3]] })
  end

  def set(o, path, value)

    Dense::Path.new(path)
      .gather(o)
      .each { |e|
        k = e[4]
        fail key_error(path, e) \
          if e[0] == false && (k == nil || e[3].length > 1)
        e[2][k] = value }

    value
  end

  def unset(o, path)

#    path = Dense::Path.new(path)
#    key = path.pop
#
#    case c = path.walk(o)
#    when Array then array_unset(c, key)
#    when Hash then hash_unset(c, key)
#    else fail KeyError.new("Found no collection at #{path.to_s.inspect}")
#    end

    pa = Dense::Path.new(path)

    r = pa
      .gather(o)
      .inject([]) { |a, e|
p e
        k = e[4]<commit_msg>Let Dense.set use new #gather result structure<commit_after>
module Dense; class << self

  def get(o, path)

    pa = Dense::Path.new(path)
    r = pa.gather(o).inject([]) { |a, e| a << e[2][e[3]] if e.first; a }

    pa.single? ? r.first : r
  end

  def fetch(o, path, default=::KeyError, &block)

    pa = Dense::Path.new(path)
    r = pa.gather(o).partition(&:first)

    if r[0].empty?

      return pa.narrow(
        r[1].collect { |m| call_default_block(o, path, block, m) }
      ) if block

      return pa.narrow(
        r[1].collect { |m| default }
      ) if default != KeyError

      fail key_error(path, r[1].first)
    end

    pa.narrow(r[0].collect { |e| e[2][e[3]] })
  end

  def set(o, path, value)

    Dense::Path.new(path)
      .gather(o)
      .each { |e|
        fail key_error(path, e) if e[0] == false && e[4].any?
        e[2][e[3]] = value }

    value
  end

  def unset(o, path)

#    path = Dense::Path.new(path)
#    key = path.pop
#
#    case c = path.walk(o)
#    when Array then array_unset(c, key)
#    when Hash then hash_unset(c, key)
#    else fail KeyError.new("Found no collection at #{path.to_s.inspect}")
#    end

    pa = Dense::Path.new(path)

    r = pa
      .gather(o)
      .inject([]) { |a, e|
p e
        k = e[4]
{'fraction_non_alphanumeric': 0.17534246575342466, 'fraction_numerical': 0.011350293542074364, 'mean_word_length': 2.198998748435544, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, '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': '4399265', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1020, 'n_words': 248}