map over tree function