with_global

guppyft.globals.with_global(initial_state: G, callback_func: Callable[[P], tuple[Unpack[R]] | Ret], *args: P, **kwargs: P) → tuple[G, Unpack[R]] | tuple[G, Ret]

Call a Guppy function in a context where map_global() provides global state.

Note

All calls to this function currently use the same global variable name to store and provide global state.

Parameters:
  • initial_state – The initial state of the global variable.

  • callback_func – The function to call in the global-enabled context.

  • *args – Positional arguments to pass to the function.

  • **kwargs – Keyword arguments to pass to the function.

Returns:

A tuple containing the final global state followed by the value or values returned by the called function.