hacklang

How to iterate fields of a shape in hacklang?


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) {
  ...
}

Solution

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

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