Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Obj-c

Idiom #19 Reverse a list

Reverse the order of the elements of the list x.
This may reverse "in-place" and destroy the original ordering.

@import Foundation;
x.reverseObjectEnumerator.allObjects

The reverseObjectEnumerator message creates a lightweight iterator, which at most places (e.g., in the for/in loop) can be used directly. If a full-fledged new array is needed, the allObjects message can be sent to (any) iterator.
with Ada.Containers.Vectors;
use Ada.Containers;
X.Reverse_Elements;

New implementation...
< >
programming-idioms.org