<commit_before>module RedisLike
  module Helpers
    module Lists
      def enqueue(list, item, to:, allow_create: true)
        operation = to == :head ? :unshift : :push
        items = fetch list, []
        items.method(operation).call(item)
        store list, items if allow_create || exists(list)
        llen list
      end

      def dequeue(list, from:)
        operation = from == :head ? :shift : :pop
        current = fetch list, []
        item = current.method(operation).call
        store list, current
        item
      end

      def remove_count(list, count, item, from:)
        operation = from == :tail ? :rindex : :index
        items = fetch list, []
        removed = count.times.map do
          found = items.method(operation).call(item)
          items.delete_at found if found
        end
        store list, items
        removed.compact.length
      end

      def remove_all(list, item)
        items = fetch list, []
        remove_count list, items.count(item), item, from: :head
        # remaining = items.reject { |i| i == item }
        # store list, remaining
        # items.length - remaining.length
      end
    end
  end
end<commit_msg>Added block_while_empty helper.<commit_after>module RedisLike
  module Helpers
    module Lists
      def enqueue(list, item, to:, allow_create: true)
        operation = to == :head ? :unshift : :push
        items = fetch list, []
        items.method(operation).call(item)
        store list, items if allow_create || exists(list)
        llen list
      end

      def dequeue(list, from:)
        operation = from == :head ? :shift : :pop
        current = fetch list, []
        item = current.method(operation).call
        store list, current
        item
      end

      def remove_count(list, count, item, from:)
        operation = from == :tail ? :rindex : :index
        items = fetch list, []
        removed = count.times.map do
          found = items.method(operation).call(item)
          items.delete_at found if found
        end
        store list, items
        removed.compact.length
      end

      def remove_all(list, item)
        items = fetch list, []
        remove_count list, items.count(item), item, from: :head
        # remaining = items.reject { |i| i == item }
        # store list, remaining
        # items.length - remaining.length
      end

      def block_while_empty(list, interval = 0.010)
        sleep interval until llen(list) > 0
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09755118426334805, 'fraction_numerical': 0.002007226013649137, 'mean_word_length': 1.973747016706444, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6515137', 'n_tokens_mistral': 710, 'n_tokens_neox': 696, 'n_words': 215}