Name for maybe-reversed lists?

Many of the higher order functions in Enum reduce a list (or other enumerable) into another, reversed list then reverse it back to the original order. When several of these functions are chained together, the list is reversed at every step. Sometimes the order needs reversed anyway, and sometimes the order is even unimportant.

I have for a while envisioned a “maybe-reversed list” structure that would keep track of whether it was in original or reversed order. Several operations could be performed on it, just reducing a new list and flipping the order flag, then the correct order could be selected when converting back to a regular list. Is there an established name for such a structure? I’m having a hard time finding much.

In my head I’ve been calling this a “twist” because it rhymes with “list” and invokes imagery in my head of turning the list over again and again (which is what it’s doing between steps even if the end result is actually fewer reversals).

1 Like

I don’t see why the reversal should be the property that’s encoded in the name. IMO maybe_ordered_list works better and you can always prepend not to this moniker for the goal that you have in mind here.

2 Likes

You could call it a tsil, after the pattern of naming “other end” things backwards from Purely Functional Data Structures (also the inspiration for the stdlib :queue module). :man_shrugging:

FWIW, I suspect that the “don’t reverse intermediate lists” approach might only have a narrow window of list sizes where it’s a performance advantage over a “never construct intermediate lists” approach using Stream.