The order is reversed because we accumulate to the left in wait_for_index, then do a right fold: you want to append the stream result to the accumulation here. The final results are in the wrong order.  Same with terms below.