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