I have:

```
const w, h = 640, 480
a = rand(Float32, w, h)
```

and an algorithm, which requires scanning array `a`

by row or column in all possible directions like shown here:

```
function scan4(a)
scanLine = zeros(max(w, h))
for i in 1:h
foo!(scanLine, a[:, i])
end
scanLine = zeros(max(w, h))
for i in h:-1:1
foo!(scanLine, a[:, i])
end
scanLine = zeros(max(w, h))
for i in 1:w
foo!(scanLine, a[i, :])
end
scanLine = zeros(max(w, h))
for i in w:-1:1
foo!(scanLine, a[i, :])
end
end
```

Is there a magic indexing trick, which would allow rewriting `scan4`

function avoiding repetitions to get something like this without dramatic loss of performance:

```
function scan42(a)
for indexingScheme in [colLeftRight, colRightLeft, rowTopDown, rowBottomUp]
scanLine = zeros(max(w, h))
for i in magicIndex(a, indexingScheme)
foo!(scanLine, magicSlice(a, i, indexingScheme))
end
end
end
```

Iâ€™m looking for an existing API, which does something similar, not how to write something new from scratch using macros, unless itâ€™s fairly simple and idiomatic to Julia.