<commit_before># encoding: utf-8

module Axiom
  class Relation
    module Operation

      # A class representing a grouped relation
      class Group < Relation
        include Unary
        include Equalizer.new(:operand, :attribute)

        # The grouped attribute
        #
        # @return [Attribute::Relation]
        #
        # @api private
        attr_reader :attribute

        # Initialize a grouped relation
        #
        # @param [Relation] operand
        # @param [#to_sym] name
        # @param [Enumerable<Axiom::Attribute>] attributes
        #
        # @return [undefined]
        #
        # @api private
        def initialize(operand, name, attributes)
          super(operand)
          inner      = header.project(attributes)
          @outer     = header - inner
          @attribute = Attribute::Relation.new(name, header: inner)
          @header    = @outer.extend(attribute)
        end

        # Iterate over each tuple in the set
        #
        # @example
        #   grouped = Group.new(operand, name, attributes)
        #   grouped.each { |tuple| ... }
        #
        # @yield [tuple]
        #
        # @yieldparam [Tuple] tuple
        #   each tuple in the set
        #
        # @return [self]
        #
        # @api public
        def each
          return to_enum unless block_given?
          build_index.each do |outer_tuple, inner_tuples|
            yield outer_tuple.extend(
              header,
              [attribute.new_relation(inner_tuples)]
            )
          end
          self
        end

      private

        # Build an index using every tuple in the operand
        #
        # @return [Index]
        #<commit_msg>Change Group#each to be a bit simpler to read<commit_after># encoding: utf-8

module Axiom
  class Relation
    module Operation

      # A class representing a grouped relation
      class Group < Relation
        include Unary
        include Equalizer.new(:operand, :attribute)

        # The grouped attribute
        #
        # @return [Attribute::Relation]
        #
        # @api private
        attr_reader :attribute

        # Initialize a grouped relation
        #
        # @param [Relation] operand
        # @param [#to_sym] name
        # @param [Enumerable<Axiom::Attribute>] attributes
        #
        # @return [undefined]
        #
        # @api private
        def initialize(operand, name, attributes)
          super(operand)
          inner      = header.project(attributes)
          @outer     = header - inner
          @attribute = Attribute::Relation.new(name, header: inner)
          @header    = @outer.extend(attribute)
        end

        # Iterate over each tuple in the set
        #
        # @example
        #   grouped = Group.new(operand, name, attributes)
        #   grouped.each { |tuple| ... }
        #
        # @yield [tuple]
        #
        # @yieldparam [Tuple] tuple
        #   each tuple in the set
        #
        # @return [self]
        #
        # @api public
        def each
          return to_enum unless block_given?
          build_index.each do |outer_tuple, inner_tuples|
            inner_relation = attribute.new_relation(inner_tuples)
            yield outer_tuple.extend(header, [inner_relation])
          end
          self
        end

      private

        # Build an index using every tuple in the operand
        #
        # @return [Index]
        #
{'fraction_non_alphanumeric': 0.08260616637579989, 'fraction_numerical': 0.0005817335660267597, 'mean_word_length': 1.551186943620178, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3295902', 'n_tokens_mistral': 932, 'n_tokens_neox': 905, 'n_words': 255}