hrldcpr/pcollections

PStack.reverse

Closed this issue · 2 comments

From gromop...@gmail.com on 2013-03-16T10:31:51Z

Cons-based lists in many languages are accompanied with reverse functionality which creates a cons-based list with the same elements in the reversed order. Using pcollections, I find I need this too. There's no easy alternaltive, as Collections.reverse() returns a normal List, not a PStack. So I'd appreciate if a method could be added:
PStack.reverse() returning another PStack.

The implementation should be very easy and straightforward, but I can provide a patch if you like.

Original issue: http://code.google.com/p/pcollections/issues/detail?id=23

A stack can be reversed easily already, because ConsPStack.plusAll() reverses (which is confusing but makes sense if you think about it) …so I'll close this but here's the code if anyone is looking:

ConsPStack<E> stack = …;
ConsPStack<E> reversed = ConsPStack.empty().plusAll(stack);

See also #77