HH\Asio\mf

Returns an Awaitable of Map after a filtering operation has been applied to each value in the provided KeyedTraversable

Description

namespace HH\Asio;

function mf<Tk, Tv>(
  KeyedTraversable<Tk, Tv> $inputs,
  (function(Tv):Awaitable<bool>) $callable,
): Awaitable<Map<Tk, Tv>>;

This function is similar to Map::filter(), but the filtering of the values is done using Awaitables.

This function is called mf because we are returning a map, and we are doing a filtering operation.

$callable must return an Awaitable of bool.

The keys and values in the Map of the returned Awaitable are not available until you await or join the returned Awaitable.

Parameters

Return Values

Examples

<?hh

namespace Hack\UserDocumentation\API\Examples\HH\Asio\mf;

enum COLOR: int {
  RED = 1;
  ORANGE = 2;
  YELLOW = 3;
  GREEN = 4;
  BLUE = 5;
  INDIGO = 6;
  VIOLET = 7;
}

$fruits = ImmMap {
  'Apple' => COLOR::RED,
  'Banana' => COLOR::YELLOW,
  'Grape' => COLOR::GREEN,
  'Orange' => COLOR::ORANGE,
  'Pineapple' => COLOR::YELLOW,
  'Tangerine' => COLOR::ORANGE,
};

// Similar to $times->filter(...)
// But awaits the awaitable result of the callback
// rather than using it directly
$orange_fruits = \HH\Asio\join(\HH\Asio\mf(
  $fruits,
  async ($color) ==> ($color == COLOR::ORANGE),
));

foreach($orange_fruits as $fruit => $color) {
  echo $fruit, 's are ', COLOR::getNames()[$color], "\n";
}
Output
Oranges are ORANGE
Tangerines are ORANGE