Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Associative array sorting



It sounds good, but a applies to indexes, not keys, and those aren't the same thing. Mind, I think that it would be good if, at least for purposes of expansion flags, indexes and keys were unified, so e.g. k on a regular array would return an array of indexes, and kv would interleave indexes with values (like Python enumerate), etc. But that's not the case today. 


On Fri, Jan 19, 2024 at 11:45 PM Eric Cook <llua@xxxxxxx> wrote:
On 1/19/24 14:18, Bart Schaefer wrote:
> I was just looking at this in the manual --
>
> a
>       Sort in array index order; when combined with 'O' sort in reverse
>       array index order.  Note that 'a' is therefore equivalent to the
>       default but 'Oa' is useful for obtaining an array's elements in
>       reverse order.
>
> Like (o), (a) applies after the param is turned into an ordinary
> array, so "equivalent to the default" kind of gets us off the hook,
> but this would be the obvious place to attach sorting the associative
> array by key rather than by raw hash traversal.
>

Sounds like a good idea to me.



--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author