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).