Imagine I want to create a function that, given an array of numbers, computes the square, cube, and fourth power of each number in an asynchronous fashion and returns a flattened, asynchronous sequence of all these results.
So, for example, for the input array [2, 3, 4]
, it should return an AsyncSequence
instance yielding the elements [4, 8, 16, 9, 27, 81, 16, 64, 256]
.
Then let's say, instead of computing x^2, x^3, x^4
, I would like it to compute x, x^2, x^3, ..., x^k
where k
is sort of a random integer that can be different for every x and is not known beforehand (its value comes to be known only as the powers are being computed). How would I implement such a pattern?