For simplicity, here's the code snippet that uses monads to auto unwind transforms:
```py
def compute_with_monad():
'''
This is "more code", however unwinding transform movements is automatic.
Most of the 'effort' is one-time-price in implementing the _withdelta functions, for cases where solid.origin does not quite preserve transformation lineages completely.
Thankfully, this is much easier to reason about since you only need to zero-in transformation matrix for one transform, and it is all composeable in stepwise multmatrix() and divmatrix() internally in TransformLineageMonad.
Note that this is bound to happen for some operations, such as unioning two solids.
'''
loc = dumbbell.origin
# IMPORTANT: reference must exist OUTSIDE of the with context to be able to dereference it after context unwind!
monad = TransformLineageMonad(dumbbell)
with (
monad as dum
):
# All translate/rotate/scale within the with-scope will be unwind after!
# Good for diff/union solids around the origin, and the context will restore to original position.
# Center the solid around the origin.
# center_withdelta() is already supplied in ztools lib (early experimental).
dum_at_origin, _ = dum.apply_mutably(lambda solid: center_withdelta(solid))
#show(dum_at_origin.solid.color('yellow'))
# Final reposition to be ready for rotate_extrude. It is a 2d projection now.
dum_ready_for_rotate_extrude, _ = dum_at_origin.apply_mutably(lambda solid: MonadUtilities.translate_withdelta(solid, [20, 20, 20]))
#show(dum_ready_for_rotate_extrude.solid.color('cyan'))
# Perform the projection to 2d, right before rotate_extrude.
dum_ready_for_rotate_extrude, _ = dum_ready_for_rotate_extrude.apply_mutably(lambda solid: MonadUtilities.projection_withdelta(solid))
# Give it height of 1 to show in render() F6.
#show(dum_ready_for_rotate_extrude.solid.linear_extrude(1).color('blue'))
# 2-layer caricature poop emoji.
weird_pottery_looking_thing, _ = dum_ready_for_rotate_extrude.apply_mutably(lambda shape: MonadUtilities.rotate_extrude_withdelta(shape, 180))
#show(weird_pottery_looking_thing.solid.color('orange'))
# Once context exits, all the 4x4 transform matrix will unwind.
# The result solid will "move" to the original position and orientation before context started.
show(monad.solid.color('magenta'))
```