How can I make this method more Scalalicious
I have a function that calculates the left and right node values for some collection of treeNodes given a simple node.id, node.parentId association. It's very simple and works well enough...but, well, I am wondering if there is a more idiomatic approach. Specifically is there a way to track the left/right values without using some externally tracked value but still keep the tasty recursion.
 
    /* 
     * A tree node
     */
    case class TreeNode(val id:String, val parentId: String){
        var left: Int = 0
        var right: Int = 0
    }
    
    /* 
     * a method to compute the left/right node values 
     */
    def walktree(node: TreeNode) = {
    	/* 
         * increment state for the inner function 
         */
        var c = 0
    	
        /*
         * A method to set the increment state
         */
        def increment = { c+=1; c } // poo
        
        /* 
         * the tasty inner method
         * treeNodes is a List[TreeNode]
         */
    	def walk(node: TreeNode): Unit = {
    	  node.left = increment

          /* 
           * recurse on all direct descendants 
           */
          treeNodes filter( _.parentId == node.id) foreach (walk(_))

          node.right = increment
    	}

    	walk(node)
    }

    walktree(someRootNode)
How can I make this method more Scalalicious
===

I have a function that calculates the left and right node values for some collection of treeNodes given a simple node.id, node.parentId association. It's very simple and works well enough...but, well, I am wondering if there is a more idiomatic approach. Specifically is there a way to track the left/right values without using some externally tracked value but still keep the tasty recursion.
 
    /* 
     * A tree node
     */
    case class TreeNode(val id:String, val parentId: String){
        var left: Int = 0
        var right: Int = 0
    }
    
    /* 
     * a method to compute the left/right node values 
     */
    def walktree(node: TreeNode) = {
    	/* 
         * increment state for the inner function 
         */
        var c = 0
    	
        /*
         * A method to set the increment state
         */
        def increment = { c+=1; c } // poo
        
        /* 
         * the tasty inner method
         * treeNodes is a List[TreeNode]
         */
    	def walk(node: TreeNode): Unit = {
    	  node.left = increment

          /* 
           * recurse on all direct descendants 
           */
          treeNodes filter( _.parentId == node.id) foreach (walk(_))

          node.right = increment
    	}

    	walk(node)
    }

    walktree(someRootNode)