reversedView property
List<T>
reversedView
Returns a List of the objects in this list in reverse order. Very efficient since it returns a view (which means, if you change the original list this one will also change, and vice-versa).
Note: List.reversed
returns an Iterable
, while List.reversedView
returns
a List
. This difference is important because if you do list.reversed.toList()
you don't have a view anymore, and it's not efficient.
Beware when using reversedView with NNBD:
// The runtimeType here is <int>, not <int?>
List<int?> reversed = [1, 2, 3].reversedView;
// The runtimeType here is <int?>
List<int?> reversed = <int ?>[1, 2, 3].reversedView;
Implementation
List<T> get reversedView => ReversedListView<T>(this);