zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Feature request: two level sorting
Date: Wed, 15 Jun 2016 20:25:06 +0200	[thread overview]
Message-ID: <CAHYJk3Qaq6zUDuCNKMS5vbznA3YWnKT6q9d5mcGn7CCFEQ-Hrg@mail.gmail.com> (raw)
In-Reply-To: <160615101239.ZM21280@torch.brasslantern.com>

On Wed, Jun 15, 2016 at 7:12 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Jun 15,  7:13am, Sebastian Gniazdowski wrote:
> }
> } # print -rl -- ${(o)files[@]}
> } aaa-A
> } aab-B
> } aac-A
> } aad-C
> }
> } when sorted with grouping on A, this will be:
> }
> } aaa-A
> } aac-A
> } aab-B
> } aad-C
>
> In a follow-on message you compare this to SQL GROUP BY, but you're
> conveniently ignoring that GROUP BY works on rows of data in columms
> whereas here you're asking for something that works on arrays of
> strings.
>
> "Feature request: A one-line parameter expansion that converts an
> array to a two-dimensional array by parsing with a pattern match,
> sorts the 2d array on one axis using multiple values of the other
> axis, and then reassembles the original one-dimensional array
> elements again in the new ordering."
>
> Can you even suggest a syntax for this that wouldn't look worse than
> the "for" loop you already wrote?
>
> } **The thing is** that it is easy to provide group names in separate
> } array:
> }
> } # groups=( "${files[@]//(#b)*([A-Z])/$match[1]}" )
>
> OK, let's examine that for a second.  What can't easily be done in the
> general case might be easily done in the specific.  Can you choose a
> delimiter of some kind that will never appear in $match[1] ?  Let's
> try ":" for this example.
>
>     groups=( "${files[@]//(#b)*([A-Z])(#m)/${match[1]}:$MATCH}" )
>
> Now:
>
>     print -rl -- "${(@)${(@o)groups}#*:}"
>
> And there you go.  It can even be written without the extra array:
>
> print -rl -- "${(@)${(@o)${files[@]//(#b)*([A-Z])(#m)/${match[1]}:$MATCH}}#*:}"
>
> But it would be horrible to try to make a generic sorting flag that
> can be passed the pattern plus the fields on which to group plus the
> sort order to apply to the result.

Can we do what the oe:: flag does for globbing? Ie, pass each element
to a custom code snippet that transforms it arbitrarily, and sort on
the output.

-- 
Mikael Magnusson


  reply	other threads:[~2016-06-15 18:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15  5:13 Sebastian Gniazdowski
2016-06-15  5:21 ` Sebastian Gniazdowski
2016-06-15  6:10   ` Sebastian Gniazdowski
2016-06-15 17:12 ` Bart Schaefer
2016-06-15 18:25   ` Mikael Magnusson [this message]
2016-06-15 22:38     ` Bart Schaefer
2016-06-15 23:02       ` Mikael Magnusson
2016-06-16 15:43         ` Bart Schaefer
2016-07-01  7:16         ` Sebastian Gniazdowski
2016-07-01 16:43           ` Bart Schaefer
2016-07-02  4:09             ` Sebastian Gniazdowski
2016-07-02 17:18               ` Bart Schaefer
2016-06-16  4:53   ` Sebastian Gniazdowski
2016-06-16  7:21     ` Bart Schaefer
2016-06-18 10:56       ` Sebastian Gniazdowski
2016-06-19 17:42         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHYJk3Qaq6zUDuCNKMS5vbznA3YWnKT6q9d5mcGn7CCFEQ-Hrg@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).