Captures the nesting structure of an object as an opaque RTree.
Each leaf in the input corresponds to its position in the flat list produced
by flatten(). The resulting tree can be passed to unflatten() to
reconstruct the original structure from a flat list.
NULL is an empty node: it holds no leaf and contributes nothing to the
flat list, but is preserved in the tree (so list(x, NULL) and
list(NULL, x) have distinct trees).
The RTree and its operations are pjrt's R analog of
JAX's pytree, which is
where the idea comes from.