Your apparently-scalar UDF doesn’t make sense IMHO, because it is inherently table-valued. Write a proper table valued function, perhaps returning a single row, and (cross) join on it, as usual, to “step” it. No ordering issue then!
Your apparently-scalar UDF doesn’t make sense IMHO, because it is inherently table-valued. Write a proper table valued function, perhaps returning a single row, and (cross) join on it, as usual, to “step” it. No ordering issue then!