Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

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.

x.reverse();

x has type Vec.

This reverses in place.
let y: Vec<_> = x.into_iter().rev().collect();

x is moved.

Works with other data structures that implement Iterator.
with Ada.Containers.Vectors;
use Ada.Containers;
X.Reverse_Elements;

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