Skip to content

Add sort function? #2

Description

$cmp = sub { ... }; # where $a/$b = [$k, $v]

$oh->sort( $comparator );

Or should users just create sorted copies with clone and
their own list of keys?

If adding a sort, should it optionally take Schwartzian
tranform arguments for efficiency/utility?

$oh->sort( $cmp, $xin, $xout );

Essentially, default $xin and $xout are these:

$xin  = sub { [ $_, $_[0]->{$_} ] };
$xout = sub { $_->[0] };

Called like this:

@keys = map { $xout->($self) } sort $cmp map { $xin->($self) };

This might be a lot more complexity and indirection vs just using clone:

$oh = $oh->clone( map { ... } sort { ... } map { ... } $oh->keys );

So maybe not allowing custom $xin and $xout is best, but do a ST internally
to [$k, $v] for a bit of flexibility in ordering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions