code: def clear_if_finalized(
          iteration: TransitionResult,
  ) -> TransitionResult[InitiatorPaymentState]:
      
      state = cast(InitiatorPaymentState, iteration.new_state)
  
      if state is None:
          return iteration
  
      if len(state.initiator_transfers) == 0:
          return TransitionResult(None, iteration.events)
  
      return iteration
docs: Clear the initiator payment task if all transfers have been finalized
      or expired.