Peek operation for stacks
yoavweiss opened this issue · 0 comments
yoavweiss commented
What problem are you trying to solve?
I have a spec draft in which I want to know what's the last member of a stack.
What solutions exist today?
Right now there are two ways to do that:
- Pop the member and then push it right back
- Treat the stack as a list, check that it's not empty and if so, access stack[0]
While the latter works, it feels awkward.
How would you solve it?
I think that a peek
operation that returns that member if it exists, or nothing otherwise, would be more ergonomic.
Anything else?
No response