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

Make .min and .max work on hashes #5501

Closed
p6rt opened this issue Jul 30, 2016 · 6 comments
Closed

Make .min and .max work on hashes #5501

p6rt opened this issue Jul 30, 2016 · 6 comments
Labels
RFC Request For Comments testneeded

Comments

@p6rt
Copy link

p6rt commented Jul 30, 2016

Migrated from rt.perl.org#128780 (status was 'resolved')

Searchable as RT128780$

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

From @smls

Currently, calling .min or .max on an non-empty Hash throws a spurious error​:

  ➜ say {a=>3, b=>2, c=>1}.max(*.value);
  Index out of range. Is​: 1, should be in 0..0

  ➜ say {a=>3, b=>2, c=>1}.min(*.value);
  Index out of range. Is​: 1, should be in 0..0

I think they should operate on the Hash is list context (i.e. make .max work like .list.max, and .min like .list.min).

That's what other list'y methods already do when they're used on a Hash​:

  ➜ say {a=>3, b=>2, c=>1}.grep(*.value == 3);
  (a => 3)

  ➜ say {a=>3, b=>2, c=>1}.sort(*.value)
  (c => 1 b => 2 a => 3)

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

From @lizmat

This is a side effect of min/max/minmax not using an iterator approach atm. I’m looking at making the necessary modifications, but that will be later today at the soonest.

On 30 Jul 2016, at 11​:47, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​128780]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128780 >

Currently, calling .min or .max on an non-empty Hash throws a spurious error​:

➜ say {a=>3, b=>2, c=>1}.max(*.value);
Index out of range. Is​: 1, should be in 0..0

➜ say {a=>3, b=>2, c=>1}.min(*.value);
Index out of range. Is​: 1, should be in 0..0

I think they should operate on the Hash is list context (i.e. make .max work like .list.max, and .min like .list.min).

That's what other list'y methods already do when they're used on a Hash​:

➜ say {a=>3, b=>2, c=>1}.grep(*.value == 3);
(a => 3)

➜ say {a=>3, b=>2, c=>1}.sort(*.value)
(c => 1 b => 2 a => 3)

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

From @lizmat

Fixed with 1035edb , tests needed

On 30 Jul 2016, at 11​:47, Sam S. (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Sam S.
# Please include the string​: [perl #​128780]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128780 >

Currently, calling .min or .max on an non-empty Hash throws a spurious error​:

➜ say {a=>3, b=>2, c=>1}.max(*.value);
Index out of range. Is​: 1, should be in 0..0

➜ say {a=>3, b=>2, c=>1}.min(*.value);
Index out of range. Is​: 1, should be in 0..0

I think they should operate on the Hash is list context (i.e. make .max work like .list.max, and .min like .list.min).

That's what other list'y methods already do when they're used on a Hash​:

➜ say {a=>3, b=>2, c=>1}.grep(*.value == 3);
(a => 3)

➜ say {a=>3, b=>2, c=>1}.sort(*.value)
(c => 1 b => 2 a => 3)

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

From @zoffixznet

Tests added in Raku/roast@9b9c39ae08

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Jul 30, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 30, 2016
@p6rt p6rt added RFC Request For Comments testneeded labels Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments testneeded
Projects
None yet
Development

No branches or pull requests

1 participant