de-tangle `new_object`
commitc67a490440219e19c3300d5a9e22be569d3b1b61
authorCatherine Gasnier <catg@fb.com>
Tue, 21 Apr 2020 08:40:39 +0000 (21 01:40 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 21 Apr 2020 08:52:24 +0000 (21 01:52 -0700)
tree7bcf865580931c526397df7a01b2b58f9879b981
parentd3488f06026261caa9986a04ced82fb7f73e22ec
de-tangle `new_object`

Summary:
`new_object` is written using a recursive function, but behind the scene this is essentially a `fold_map`.
Rewriting it using `fold_map` exposes the essence of what's happening, e.g. allows to show that we really only retain the last encountered `tel` and `typed_unpacked_element` (whether that's correct is another story).
We also don't need the `finish` local function anymore and can simply inline it, which makes for a more natural order of the code.
Besides, since `finish` wasn't doing anything with its `tcid` parameter besides returning it, we don't need to pass it to and return it from `gather` either.

This should also help porting that code to rust

Bonus: a few renaming, commenting and type annotations.

Reviewed By: vsiles

Differential Revision: D21129762

fbshipit-source-id: 375014f9d62fc6e83aea6d2b7d3ac8a7ef9df2d1
hphp/hack/src/typing/typing.ml