IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python function

map

map()

max.experimental.tree_utils.map(f, tree, *rest, leaf=None, shared=False)

source

Builds a new tree with each leaf replaced by what f returns.

With extra trees in rest, f receives one leaf from each.

Parameters:

  • f (Callable[[...], Any]) – Applied to one leaf from tree and one from each of rest.
  • tree (Any) – The structure whose leaves are mapped.
  • rest (Any) – More trees, each with tree’s structure.
  • leaf (type | tuple[type, ...] | Callable[[Any], bool] | None) – Where the walk stops.
  • shared (bool) – Whether an aliased value is one leaf or one per path. Set, f runs once per distinct leaf and rest must alias in the same places.

Returns:

A new tree with tree’s structure, holding the mapped leaves.

Raises:

ValueError – If a tree in rest does not match tree’s structure.

Return type:

Any