-
Notifications
You must be signed in to change notification settings - Fork 15
Inconsistent treatment of iterable argument #35
Comments
I'd personally be in favor of always preferring the |
If we intend |
That's a fair point. |
Thanks for the feedback, Adam!
In
Just to confirm that we're thinking of the same solution here -- this would mean just removing the |
For |
Even if the set is always iterated over; does it make sense to require the |
Yeah, that's the thought. Though it's a little weird to still use the potentially overridden const $Set = Set;
const $has = Function.prototype.call.bind(Set.prototype.has);
Set.prototype.isSubsetOf = function(iterable) {
const set = new $Set(iterable);
for (const e of this.[[SetData]]) { // not sure whether to use [[SetData]] or Symbol.iterator
if (!has(set, e)) {
return false;
}
}
return true;
}; Another alternative would be to make it a "protocol" like thenables - don't check anything, don't accept iterables, just invoke
I don't think so. |
I think the back-and-forth above is useful, just wanted to chime in with some more understanding I have after @gsathya's reply (and some offline discussion):
This makes it clear that |
@bakkot ah, i guess what i meant was, before getting |
I think it makes sense for these methods to "mean the same thing" by the above terms: so however Having That makes (I would also be OK with having "membership testing" mean "look at at the This differs from the strategy I was suggesting above, in that I am now suggesting "always assume it's a set and call |
Short version of above comment:
|
Fixed in #41 |
All the methods in this proposal take a single argument,
iterable
. But there are two different treatments of that argument:iterable
to get at its elements.isXXX
operations (except forisSupersetOf
), there's a check for the[[SetData]]
internal slot, and if it's already a Set, then no iteration is performed (instead, the receiver's[[SetData]]
is, unobservably, iterated). For non-Set iterables, a new Set is constructed (which will, of course, run the iteration protocol itself).Why are there two different approaches here? If possible, it would be ideal for these methods to deal with their argument in a uniform manner.
The text was updated successfully, but these errors were encountered: