How to iterate fields of a shape in hacklang?

Viewed 933

Say I have a shape like this

$something = shape(
  'some_key' => ...,
  'another_key' => ...,
  ...
);

How can I iterate each field of the shape? I'm looking for something like this

foreach ($something as $key) {
  ...
}
1 Answers

Convert to a dict first with the built-in HH\Shapes::toDict then iterate:

foreach(HH\Shapes::toDict($something) as $k => $v) {
  // ...
}
Related