code: def _last_in_direction(starting_pos, direction):
          
          cur_pos = None
          next_pos = starting_pos
          while next_pos is not None:
              cur_pos = next_pos
              next_pos = direction(cur_pos)
          return cur_pos
docs: move in the tree in given direction and return the last position.
  
          :param starting_pos: position to start at
          :param direction: callable that transforms a position into a position.