On Thu Sep 27 05:07:41 2018, KES wrote:
Show quoted text> by analogy pairgrep, pairmap implement pairsort:
>
> my $hash_ref = {
> name => {pos => 1},
> name_xxx => {pos => 2},
> name_yyy => {pos => 3},
> };
>
>
> my @keys = pairkeys pairsort{ $a[1]{pos} <=> $b[1]{pos} } @kvlist #
> name name_xxx name_yyy
Annoyingly, the precedent I set with pairmap / pairgrep was that $a and $b will contain the key and value of a single pair. I then fixed that by adding the Pair type and setting $_ to it, but that remains. A trouble with pairsort could be that what do $a and $b contain now?
In any case, the addition of unpairs() makes a pairsort behaviour a trivial monomorphic lift:
my @kvsorted = unpairs sort { compare $a and $b } pairs @kvlist;
By analogy the other pair* functions can easily be built similarly:
pairmap == unpairs map { ... } pairs
pairgrep == unpairs grep { ... } pairs
--
Paul Evans