HH\Set::retainWithKey

Alters the current Set so that it only contains the values that meet a supplied condition on its "keys" and values.

Description

public function retainWithKey(
  (function(mixed,Tv):bool) $callback,
): Set<Tv>

Alters the current Set so that it only contains the values that meet a supplied condition on its "keys" and values.

Sets don't have keys, so the Set values are used as the key in the callback.

This method is like filterWithKey(), but mutates the current Set too in addition to returning the current Set.

Future changes made to the current Set ARE reflected in the returned Set, and vice-versa.

Parameters

  • (function(mixed,Tv):bool) $callback - The callback containing the condition to apply to the current Set values.

Return Values