<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _last_in_direction(starting_pos, direction):
 """ 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. """

        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