module T::Props::Constructor::DecoratorMethods

def construct_props_without_defaults(instance, hash)

def construct_props_without_defaults(instance, hash)
  # Use `each_pair` rather than `count` because, as of Ruby 2.6, the latter delegates to Enumerator
  # and therefore allocates for each entry.
  result = 0
  props_without_defaults&.each_pair do |p, setter_proc|
    begin
      val = hash[p]
      instance.instance_exec(val, &setter_proc)
      if val || hash.key?(p)
        result += 1
      end
    rescue TypeError, T::Props::InvalidValueError
      if !hash.key?(p)
        raise ArgumentError.new("Missing required prop `#{p}` for class `#{instance.class.name}`")
      else
        raise
      end
    end
  end
  result
end