<commit_before>module Veritas
  class Relation
    module Operation
      class Order
        class DirectionSet
          include Enumerable

          def initialize(directions)
            @directions = Array(directions).map do |direction|
              Ascending.coerce(direction)
            end
          end

          def reverse
            self.class.new(map { |direction| direction.reverse })
          end

          def each(&block)
            to_ary.each(&block)
            self
          end

          def to_ary
            @directions
          end

          def union(other)
            self.class.new(to_ary | other.to_ary)
          end

          alias | union

          def attributes
            map { |direction| direction.attribute }
          end

          def sort(tuples)
            tuples.sort { |left, right| cmp_tuples(left, right) }
          end

          def ==(other)
            other = self.class.coerce(other)
            to_ary == other.to_ary
          end

          def eql?(other)
            instance_of?(other.class) &&
            to_ary.eql?(other.to_ary)
          end

          def hash
            @hash ||= to_ary.hash
          end

          def empty?
            @directions.empty?
          end

        private

          def cmp_tuples(left, right)
            each do |direction|
              cmp = direction.call(left, right)
              return cmp if cmp != 0
            end
          end

          def self.coerce(object)
            object.kind_of?(DirectionSet) ? object : new(object)
          end

        end # class DirectionSet
      end # class Order
    end # module Operation
  end # class Relation
end # module Veritas<commit_msg>Use Fixnum#nonzero? to clean up cmp_tuples a bit<commit_after>module Veritas
  class Relation
    module Operation
      class Order
        class DirectionSet
          include Enumerable

          def initialize(directions)
            @directions = Array(directions).map do |direction|
              Ascending.coerce(direction)
            end
          end

          def reverse
            self.class.new(map { |direction| direction.reverse })
          end

          def each(&block)
            to_ary.each(&block)
            self
          end

          def to_ary
            @directions
          end

          def union(other)
            self.class.new(to_ary | other.to_ary)
          end

          alias | union

          def attributes
            map { |direction| direction.attribute }
          end

          def sort(tuples)
            tuples.sort { |left, right| cmp_tuples(left, right) }
          end

          def ==(other)
            other = self.class.coerce(other)
            to_ary == other.to_ary
          end

          def eql?(other)
            instance_of?(other.class) &&
            to_ary.eql?(other.to_ary)
          end

          def hash
            @hash ||= to_ary.hash
          end

          def empty?
            @directions.empty?
          end

        private

          def cmp_tuples(left, right)
            each do |direction|
              cmp = direction.call(left, right)
              return cmp if cmp.nonzero?
            end
          end

          def self.coerce(object)
            object.kind_of?(DirectionSet) ? object : new(object)
          end

        end # class DirectionSet
      end # class Order
    end # module Operation
  end # class Relation
end # module Veritas
{'fraction_non_alphanumeric': 0.06968039159228333, 'fraction_numerical': 0.00028793550244745177, 'mean_word_length': 1.2720732504905168, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3829433', 'n_tokens_mistral': 944, 'n_tokens_neox': 908, 'n_words': 237}