<commit_before># Messing around with building my own Enumerator class using Fiber.

require "fiber"

class FiberEnumerator
  include Enumerable

  def initialize(&block)
    @fiber = Fiber.new do
      block.call(Yielder)
      raise "I'm done"
    end
  end

  def next
    @fiber.resume
  end

  def each(&block)
    while @fiber.alive?
      block.call(self.next)
    end
  end

  class Yielder
    def self.<<(value)
      Fiber.yield(value)
    end
  end
end
<commit_msg>Do the Exception handling so FiberEnumerator works like a real Enumerator.<commit_after># Messing around with building my own Enumerator class using Fiber.

require "fiber"

class FiberEnumerator
  include Enumerable

  def initialize(&block)
    @fiber = Fiber.new do
      block.call(Yielder)
      raise StopIteration
    end
  end

  def next
    @fiber.resume
  end

  def each(&block)
    begin
      while true
        block.call(self.next)
      end
    rescue StopIteration
    end
  end

  class Yielder
    def self.<<(value)
      Fiber.yield(value)
    end
  end
end

{'fraction_non_alphanumeric': 0.06912878787878787, 'fraction_numerical': 0.0, 'mean_word_length': 2.546979865771812, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1026616', 'n_tokens_mistral': 363, 'n_tokens_neox': 344, 'n_words': 107}