<commit_before>module Indexable(T)
  abstract def size
  abstract def unsafe_at(index : Int)

  def at(index : Int)
    index = check_index_out_of_bounds index do
      return yield
    end
    unsafe_at index
  end

  @[AlwaysInline]
  def at(index : Int)
    at(index) { panic "Invalid index!" }
  end

  @[AlwaysInline]
  def [](index : Int)
    at index
  end

  @[AlwaysInline]
  def []?(index : Int)
    at index { nil }
  end

  @[AlwaysInline]
  def []=(index : Int, value : T)
    index = check_index_out_of_bounds index
    @buffer[index] = value
  end

  def each
    each_index do |i|
      yield unsafe_at i
    end
  end

  def each_index
    i = 0
    while i < size
      yield i
      i += 1
    end
    self
  end

  def empty?
    size == 0
  end

  private def check_index_out_of_bounds(index)
    check_index_out_of_bounds(index) { panic "Index out of bounds!" }
  end

  private def check_index_out_of_bounds(index)
    index += size if index < 0
    if 0 <= index < size
      index
    else
      yield
    end
  end
end
<commit_msg>Fix a bug in Indexable(T) This fixes a bug where calling `Indexable(T).[]?` wouldn't compile.<commit_after>module Indexable(T)
  abstract def size
  abstract def unsafe_at(index : Int)

  def at(index : Int)
    index = check_index_out_of_bounds index do
      return yield
    end
    unsafe_at index
  end

  @[AlwaysInline]
  def at(index : Int)
    at(index) { panic "Invalid index!" }
  end

  @[AlwaysInline]
  def [](index : Int)
    at index
  end

  @[AlwaysInline]
  def []?(index : Int)
    at(index) { nil }
  end

  @[AlwaysInline]
  def []=(index : Int, value : T)
    index = check_index_out_of_bounds index
    @buffer[index] = value
  end

  def each
    each_index do |i|
      yield unsafe_at i
    end
  end

  def each_index
    i = 0
    while i < size
      yield i
      i += 1
    end
    self
  end

  def empty?
    size == 0
  end

  private def check_index_out_of_bounds(index)
    check_index_out_of_bounds(index) { panic "Index out of bounds!" }
  end

  private def check_index_out_of_bounds(index)
    index += size if index < 0
    if 0 <= index < size
      index
    else
      yield
    end
  end
end

{'fraction_non_alphanumeric': 0.0847380410022779, 'fraction_numerical': 0.004555808656036446, 'mean_word_length': 2.38366718027735, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '4993273', 'n_tokens_mistral': 799, 'n_tokens_neox': 768, 'n_words': 242}