How to iterate fields of a shape in hacklang?

1.8k Views Asked by At

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

There are 1 best solutions below

0
concat On BEST ANSWER

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

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