transient vectors should support the stack interface (peek/pop)

Description

Appears to be an oversight, given that peek is a read operation.

Input:

Expected outcome:

Actual outcome:

Environment

None

Activity

Show:
Steve Miner
February 19, 2019, 8:16 PM

I just ran into this issue today. I agree it would be convenient if peek worked on a transient vector. Other functions such as nth and count work on transient vectors, so it's natural to want peek.

As a work-around (not a suggested fix), I use this:

Admittedly, that's a misnomer but it fits the bang pattern for transient transformation of regular collection code. I also have a convenience function update! which calls assoc!. I offer the work-around just for users who run into this problem and want to get back to work.

Alex Miller
February 19, 2019, 10:40 PM

I think this would mean PersistentVector.TransientVector would need to support IPersistentStack but that has two methods - peek and pop. Interestingly, ITransientVector and TransientVector both have pop() already. Seems like the pop() impl has all the smarts you'd need to implement peek() too.

Alex Miller
August 23, 2019, 8:02 PM

Side note that IPersistentStack extends IPersistentCollection, and I don't think we'd want to have TransientVector implement IPC (as it's not persistent). So, would either need to introduce some custom logic to RT.peek()/pop() or introduce an ITransientStack interface line.

Retargeting this as new feature rather than bug.

Assignee

Unassigned

Reporter

import

Labels

Approval

Triaged

Patch

None

Affects versions

Priority

Major
Configure