HH\Lib\C\reduce_with_key

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

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

Reduces the given KeyedTraversable into a single value by applying an accumulator function against an intermediate result and each key/value

namespace HH\Lib\C;

function reduce_with_key<Tk, Tv, Ta>(
  KeyedTraversable<Tk, Tv> $traversable,
  (function(Ta, Tk, Tv): Ta) $accumulator,
  Ta $initial,
): Ta;

Time complexity: O(n) Space complexity: O(1)

Parameters

Returns

  • Ta