DimensionalData: how to map slices, while using non-slice dimensions

I’ve got a multidimensional DimArray and want to map a function that summarizes across one of the dimensions. This is simple to do using mapslices, e.g.

using DimensionalData
arr = rand(X(1:10), Y(1:20), Z(1:30))
f(z) = sum(z)
mapslices(f, arr, dims=:Z)

However, I have a function that also depends on the values of x and y at each slice, something like

f(x, y, zs) = sin(x) + cos(y) + sum(zs)

What’s the best way to map this function across the all the Z slices of the array? I’ve got this,

[f(x, y, arr[X(At(x)), Y(At(y))]) 
    for (x, y) in Iterators.product(collect.(otherdims(arr, :Z))...)]

but was hoping there might be a more streamlined solution, preferably one that would generalize for higher-dimensional arrays as well…

Also worked this out, which seems like an improvement. Any better ideas?

f(coords, zs) = sum(coords) + sum(zs)
dims = otherdims(arr, :Z)
[f(coords, arr[I...]) for (coords, I) in zip(DimPoints(dims), DimKeys(dims))]