Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort function? #2

Open
dagolden opened this issue Jul 2, 2014 · 0 comments
Open

Add sort function? #2

dagolden opened this issue Jul 2, 2014 · 0 comments

Comments

@dagolden
Copy link
Collaborator

dagolden commented Jul 2, 2014

$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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants