Requires the Hack Standard Library to be installed.
Facebook Engineer?

This function is available as C\last() in Facebook's www repository.

Returns the last element of the given Traversable, or null if the Traversable is empty

namespace HH\Lib\C;

function last<T>(
  Traversable<T> $traversable,
): ?T;
  • For non-empty Traversables, see C\lastx.
  • For single-element Traversables, see C\onlyx.

Time complexity: O(1) if $traversable is a Container, O(n) otherwise. Space complexity: O(1)



  • ?T