InfluxDB Flux - Getting last and first values as a column

I am trying to create two new columns with the first and last values using the last() and first() functions. However the function isn’t working when I try to map the new columns. Here is the sample code below. Is this possible using Flux?

from(bucket: "bucket")

  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "price_info")
  |> filter(fn: (r) => r["_field"] == "price")
  |> map(fn: (r) => ({r with  
  open: last(float(v: r._value)),
  close: first(float(v: r._value)),
  })

IIUC, first and last operate on tables. map works that way too, and it applies the function to every row (?; Not sure about the correct terminology). That’s why it’s probably not working.

I think there are two ways to do what you want:

First, is too create two tables; I’ve got first and one for last and join them.

Second, is to write your own accumulator using reduce().

Ideally, the second one would be easier, but there don’t seem to be any higher order functions to apply multiple accumulators at the same time. Hopefully, that will be added (or I just missed it).