Loop over query results in a macro
To convert the results of an Element Query into a custom key/value array you can use the index filter to specify what you want to use as the keys. So for example if you want the category slugs to be the keys and the category titles to be the values you'd do it like this:
{% set indexedCats = craft.categories.all()|index('slug') %}
{{ macro.select('name', indexedCats }}

=================

output:

&lt;select name=&quot;name&quot;&gt;
    &lt;option value=&quot;cat-slug-1&quot;&gt;Cat Title 1&lt;/option&gt;
    &lt;option value=&quot;cat-slug-2&quot;&gt;Cat Title 2&lt;/option&gt;
&lt;/select&gt;

Swap in 'title' if you want the key and value to both be the same.