code: func NewStateMachine(stateMachineName string,
  	startState TransitionState) *StateMachine {
  	uniqueStates := make(map[string]MachineState)
  	pendingStates := []MachineState{startState}
  	duplicateStateNames := make(map[string]bool)
  
  	nodeVisited := func(node MachineState) bool {
  		if node == nil {
  			return true
  		}
  		_, visited := uniqueStates[node.Name()]
  		return visited
  	}
  
  	for len(pendingStates) != 0 {
  		headState, tailStates := pendingStates[0], pendingStates[1:]
  		uniqueStates[headState.Name()] = headState
  
  		switch stateNode := headState.(type) {
  		case *ChoiceState:
  			for _, eachChoice := range stateNode.Choices {
  				if !nodeVisited(eachChoice.nextState()) {
  					tailStates = append(tailStates, eachChoice.nextState())
  				}
  			}
  			if !nodeVisited(stateNode.Default) {
  				tailStates = append(tailStates, stateNode.Default)
  			}
  
  		case TransitionState:
  			for _, eachAdjacentState := range stateNode.AdjacentStates() {
  				if !nodeVisited(eachAdjacentState) {
  					tailStates = append(tailStates, eachAdjacentState)
  				}
  			}
  			// Are there any Catchers in here?
  		}
  		pendingStates = tailStates
  	}
  
  	// Walk all the states and assemble them into the states slice
  	sm := &StateMachine{
  		name:         stateMachineName,
  		startAt:      startState,
  		uniqueStates: uniqueStates,
  	}
  	// Store duplicate state names
  	if len(duplicateStateNames) != 0 {
  		sm.stateDefinitionError = fmt.Errorf("duplicate state names: %#v", duplicateStateNames)
  	}
  	return sm
  }
docs: // NewStateMachine returns a new StateMachine instance