# tff.framework.transform_preorder

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Walks the AST of `comp` preorder, calling `transform` on the way down.

    tff.framework.transform_preorder(
        comp: https://www.tensorflow.org/federated/api_docs/python/tff/framework/ComputationBuildingBlock,
        transform: Callable[[building_blocks.ComputationBuildingBlock], TransformReturnType]
    ) -> https://www.tensorflow.org/federated/api_docs/python/tff/framework/ComputationBuildingBlock

Notice that this function will stop walking the tree when its transform
function modifies a node; this is to prevent the caller from unexpectedly
kicking off an infinite recursion. For this purpose the transform function
must identify when it has transformed the structure of a building block; if
the structure of the building block is modified but `False` is returned as
the second element of the tuple returned by `transform`, `transform_preorder`
may result in an infinite recursion.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `comp` | Instance of `building_blocks.ComputationBuildingBlock` to be transformed in a preorder fashion. |
| `transform` | Transform function to be applied to the nodes of `comp`. Must return a two-tuple whose first element is a `building_blocks.ComputationBuildingBlock` and whose second element is a Boolean. If the computation which is passed to `comp` is returned in a modified state, must return `True` for the second element. This Boolean controls whether or not to stop traversing the tree under `comp`; if this Bool is `True`, `transform_preorder` will not traverse this subtree. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A two-tuple, whose first element is modified version of `comp`, and whose second element is a Boolean indicating whether `comp` was transformed during the walk. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If the argument types don't match those specified above. |

<br />