Flattens a function taking in possibly nested RTree objects so it takes in flat inputs
and return flat outputs (along the returned tree structure).
Examples
f <- function(x) list(sum = x$a + x$b)
ff <- flatten_fun(f, build_tree(list(list(a = 1, b = 2))))
ff(3, 4)
#> [[1]]
#> list<named>(sum = *)
#>
#> [[2]]
#> [[2]][[1]]
#> [1] 7
#>
#>