def _fn_to_return(arg, param_fns, wrapped_fn):
    param_elements = []
    if (arg is not None):
        arg_parts = structure.flatten(arg)
        if (len(arg_parts) != len(param_fns)):
            raise RuntimeError('Expected {} arguments, found {}.'.format(len(param_fns), len(arg_parts)))
        for (arg_part, param_fn) in zip(arg_parts, param_fns):
            param_elements.append(param_fn(arg_part))
    result_parts = wrapped_fn(*param_elements)
    resources = []
    for op in wrapped_fn.graph.get_operations():
        if (op.type == 'VarHandleOp'):
            resources += op.outputs
    if resources:
        for resource in wrapped_fn.prune(feeds={}, fetches=resources)():
            tf.raw_ops.DestroyResourceOp(resource=resource)
    result_elements = []
    for (result_part, result_fn) in zip(result_parts, result_fns):
        result_elements.append(result_fn(result_part))
    return structure.pack_sequence_as(result_type, result_elements)
def _fn_to_return(arg, param_fns, wrapped_fn):
    param_elements = []
    if (arg is not None):
        arg_parts = structure.flatten(arg)
        if (len(arg_parts) != len(param_fns)):
            raise RuntimeError('Expected {} arguments, found {}.'.format(len(param_fns), len(arg_parts)))
        for (arg_part, param_fn) in zip(arg_parts, param_fns):
            param_elements.append(param_fn(arg_part))
    result_parts = wrapped_fn(*param_elements)
    resources = []
    for op in wrapped_fn.graph.get_operations():
        if (op.type == 'VarHandleOp'):
            resources += op.outputs
    if resources:
        for resource in wrapped_fn.prune(feeds={}, fetches=resources)():
            tf.raw_ops.DestroyResourceOp(resource=resource)
    result_elements = []
    for (result_part, result_fn) in zip(result_parts, result_fns):
        result_elements.append(result_fn(result_part))
    return structure.pack_sequence_as(result_type, result_elements)