Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

How about Set.prototype.pop() or Set.prototype.last? #55

Closed
doasync opened this issue Jan 17, 2019 · 13 comments
Closed

How about Set.prototype.pop() or Set.prototype.last? #55

doasync opened this issue Jan 17, 2019 · 13 comments

Comments

@doasync
Copy link

doasync commented Jan 17, 2019

No description provided.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

What's the use case? Sets have insertion order, but beyond being deterministic, the ordering isn't usually relevant in code i've seen.

@doasync
Copy link
Author

doasync commented Jan 17, 2019

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

That's asking how to do it; it doesn't contain a use case that I can see. Can you be more specific?

@doasync
Copy link
Author

doasync commented Jan 17, 2019

To implement Stack (Last In First Out) behaviour

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

If you're wrapping a Set, then you could wrap the add method to keep track of the last item added, no?

@doasync
Copy link
Author

doasync commented Jan 17, 2019

Yes, but why bother to wrap it. The only method we need to manage stacks with sets is .pop()

@doasync doasync changed the title How about Set.prototype.last? How about Set.prototype.pop() or Set.prototype.last? Jan 17, 2019
@doasync
Copy link
Author

doasync commented Jan 17, 2019

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

Sets aren't a stack tho, they're a set. Arrays are stacklike as well; is there a reason a Set is needed when an Array already has that semantic?

@doasync
Copy link
Author

doasync commented Jan 17, 2019

A value in the Set may only occur once; it is unique in the Set's collection.

@zloirock
Copy link
Contributor

Current proposal contains methods based on set theory, so it's rather an issue for https://github.com/tc39/proposal-collection-methods. Also, I agree with @ljharb argumentation.

@ljharb
Copy link
Member

ljharb commented Jan 17, 2019

@doasync sure but that's not a property of stacks, it's a property of sets.

@doasync
Copy link
Author

doasync commented Jan 17, 2019

Yeah, ok, thanks

@doasync doasync closed this as completed Jan 17, 2019
@doasync
Copy link
Author

doasync commented Jan 17, 2019

They already have an issue about .pop:
tc39/proposal-collection-methods#1

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

No branches or pull requests

3 participants