fix applyLast and applyRight for n-ary functions