last function

dynamic last(
  1. dynamic value
)

Returns the last element of value.

  • Supports List, Map, and Set.
  • For maps, returns the last entry.
  • Throws Exception if value is not a supported type.

Implementation

dynamic last(dynamic value) {
  if (value is List) return value.last;
  if (value is Map) return value.last();
  if (value is Set) return value.last;
  throw Exception("Function 'last' is invalid for type "
      "'${value.runtimeType}'. Valid types are List, Map, and Set.");
}