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

This function is available as Vec\filter() in Facebook's www repository.

Returns a new vec containing only the values for which the given predicate returns true

namespace HH\Lib\Vec;

function filter<Tv>(
  Traversable<Tv> $traversable,
  ?(function(Tv): bool) $value_predicate = NULL,
): vec<Tv>;

The default predicate is casting the value to boolean.

Time complexity: O(n * p), where p is the complexity of $value_predicate Space complexity: O(n)



  • vec<Tv>