The existence of `Set#first` is an artifact of Set including Enumerable =
and the very idea of "first" on a Set is an odd notion. A set by itself =
does not have ordering. I have implemented it to pick the first element =
because it is simplest, but someone calling "pick" on a set does not =
care which element it is. If one would prefer implementing it as an =
alias, I'd be fine with that.

On a personal note, one reason I enjoy using Ruby because often my code =
reads just as I would describe it to a colleague - reading "element =3D =
set.first" is not something many would agree is a sensible way to =
describe the act of picking an arbitrary element from a mathematical =
set.

And yes, one could implement #pop with #delete and #first, which again =
relies on a notion of ordering in a set. One can implement =
#proper_subset with #subset and a comparison, as can one implement =
#proper_superset with #supserset and a comparison. Yet they are in the =
Set class because they are fundamental operations. #add? and #delete? =
can also be implemented with #add and #include?/#delete and #include? =
respectively, yet they are included in the Set class because they are =
useful and common operations on a set.

If `pop` is too close the Array method of the same name, I understand =
the confusion, but I don't get why picking first/last makes a =
difference. Anyone asking to remove an arbitrary element from a Set =
surely doesn't care where it lies in an underlying hash table. I am =
surprised one would argue that the Set class rarely needs the notion of =
selecting an element from it. Rarely am I presented with an algorithm =
using sets that does not require simply getting an element or picking =
one out of a set.

Michael Edgar
adgar / carboni.ca
http://carboni.ca/

On Apr 7, 2011, at 2:40 PM, Marc-Andre Lafortune wrote:

> Hi.
>=20
> There is no difference between your `Set#pick` and the existing =
`Set#first`. As such, there is no need for `pick`.
>=20
> One can get the effect of `Set#pop` by calling the existing =
`Set#delete` with the result of `Set#first` (with the same O(1) =
efficiency).
>=20
> I find problematic that a method called `pop` would take the first =
element; it could be renamed to `shift`, say, or take the last element =
instead. More importantly, though, I am not convinced that this =
functionality is that frequently used.