# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Interactively fold a tree

Contributed by:
Ian Ford

ResourceFunction["TreeFoldInteractive"][ successively folds the subtrees of | |

ResourceFunction["TreeFoldInteractive"][ applies | |

ResourceFunction["TreeFoldInteractive"][{ applies |

TreeFoldInteractive is an interactive version of TreeFold.

ResourceFunction["TreeFoldInteractive"] constructs an expression from a Tree object, folding its subtrees from the bottom up using a binary operation *f*.

ResourceFunction["TreeFoldInteractive"] is useful for accumulating or reducing the data or subtrees of a tree to a single value.

ResourceFunction["TreeFoldInteractive"] folds subtrees in a depth-first order, folding children before folding parents.

In ResourceFunction["TreeFoldInteractive"][*f*,*tree*,*h*], *h*[*tree*] is used as the first argument of *f* rather than TreeData[*tree*].

ResourceFunction["TreeFoldInteractive"][{…,*f*_{-1}},*tree*,*h*] gives *f*_{-1}[*h*[*tree*]] if *tree* is a leaf.

Interactively fold a tree with a binary function *f*:

In[1]:= |

Out[1]= |

Interactively fold a tree with a binary function *f* after applying a function *g* to the data in the leaves:

In[2]:= |

Out[2]= |

Clicking a leaf applies *g*:

In[3]:= |

Out[3]= |

Clicking an inner node folds its corresponding subtree:

In[4]:= |

Out[4]= |

Clicking the root node folds the whole tree:

In[5]:= |

Out[5]= |

Interactively fold a property of subtrees:

In[6]:= |

Out[6]= |

- Functional Iteration for Divide-and-Conquer Algorithms. Ian Ford. Wolfram Community.
- Catamorphism - Wikipedia
- Attribute grammar - Wikipedia
- Recursion (computer science) - Wikipedia
- Divide-and-conquer algorithm - Wikipedia

Wolfram Language 13.0 (December 2021) or above

- 1.0.1 – 04 March 2024
- 1.0.0 – 19 January 2024

This work is licensed under a Creative Commons Attribution 4.0 International License