Is it possible to execute the same function across multiple buckets in a single task script?

I have a scheduled task that applies a window function to a measurement series that then writes the output table to another measurement series in the same bucket. What I want to do is apply exactly the same function to multiple buckets within the same task. I know in my task script I can use buckets() to get a list of all buckets in my organisation. But I don’t see an obvious way of iterating the buckets like the following psuedo code:

customers = buckets()
|> map(fn: (r) => ({

    bucketSeries = from(bucket:
	|> range(start: -12h)
	|> filter(fn: (r) =>
		(r["_measurement"] == "mymeasurement"))
        |> aggregateWindow(...)
        |> set(key: "_measurement", value: "newmeasure")
	|> to(bucket:


Any help is much appreciated.