Skip to main content

mmkw

Note

This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information.

Returns an Awaitable of Map of ResultOrExceptionWrapper after a mapping operation has been applied to each key/value pair in the provided KeyedTraversable

namespace HH\Asio;

function mmkw<Tk as arraykey, Tv, Tr>(
KeyedTraversable<Tk, Tv> $inputs,
(function(Tk, Tv): Awaitable<Tr>) $callable,
): Awaitable<Map<Tk, ResultOrExceptionWrapper<Tr>>>;

This function is similar to mmk(), except the Map in the returned Awaitable contains values of ResultOrExceptionWrapper instead of raw values.

This function is similar to Map::mapWithKey(), but the mapping of the keys and values is done using Awaitables.

This function is called mmkw because we are returning a map, doing a mapping operation on keys and values, and each value member in the Map is wrapped by a ResultOrExceptionWrapper.

$callable must return an Awaitable.

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

Parameters

Returns

  • Awaitable<Map<Tk,ResultOrExceptionWrapper<Tr>>> - An Awaitable of Map of key/ResultOrExceptionWrapper pairs after the mapping operation has been applied to the keys an values in $inputs.

Examples

<<__EntryPoint>>
async function basic_usage_main(): Awaitable<void> {
// Map a vector of numbers to their value divided by their index
// throwing on division by zero.
$quotients = await \HH\Asio\mmkw(
Map {
1 => 1,
0 => 2,
2 => 6,
3 => 12,
},

async ($div, $val) ==> {
if ($div != 0) {
return $val / $div;
} else {
throw new \Exception(
"Division by zero: ".\print_r($val, true).'/'.\print_r($div, true),
);
}
},
);

foreach ($quotients as $result) {
if ($result->isSucceeded()) {
echo " Success: ";
\var_dump($result->getResult());
} else {
echo "Failed: ";
\var_dump($result->getException()->getMessage());
}
}
}