Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Spec .min/.max on Bags
- Loading branch information
Showing
1 changed file
with
2 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an argument that .min should always return 0? It would be very weird if
equaled 10....
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since that bag is supposed to represent a collection of 10 "a"s, I'd expect .min to return "a".
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, return 10 anyway.
While it may seem odd when you say
("a"=>10,"b"=>0).Bag.min, it might make more sense if you look at("a"=>$num_a, "b"=>$num_b).Bag.min. If$num_bis zero, there's none of them in the bag and they don't matter formin.9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To put it a slightly different way, consider
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All standard QuantHashs (BagHash, etc.) delete keys with value zero (or False etc.). This seems like classic perl think and here to stay. So colomon's example makes sense:
But then consider:
So .min on a hash (currently in Rakudo) returns the min key, ignoring the value.
And:
returns the min value, but we've lost knowing there's two such keys.
Seems like there's design work to do.
If only there were a Damian around... ;)
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9213b13There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remembering that it's extremely easy to get the min value by just saying
(likewise for
.keysand.pairs)