function is_array_of_shapes_with_name_field()

in src/TypeAssert.hack [85:99]


function is_array_of_shapes_with_name_field(
  mixed $value,
  string $field,
): varray<shape('name' => string)> {
  $msg = $field.'should be an array<shape(\'name\' => string)>';
  invariant($value is Traversable<_>, '%s', $msg);
  $out = varray[];
  foreach ($value as $it) {
    invariant($it is KeyedContainer<_, _>, '%s', $msg);
    $name = $it['name'] ?? null;
    invariant($name is string, '%s', $msg);
    $out[] = shape('name' => $name);
  }
  return $out;
}