higher order iteration for trees