A very commonly used design pattern is to apply a function to all unique pairs of elements in a container, e.g.

```
f(x,y) = x*y
a = randn(5)
ret = eltype(a)[] #the example returns a vector, but in this case an UpperTriangular Matrix might be better.
for i in 1:(length(a-1))
for j in (i+1):length(a)
push!(ret, f(a[i], a[j]))
end
end
```

(see e.g. http://julialang.org/blog/2013/09/fast-numeric for a use of pairwise), but it could also apply to all pairwise combination of columns or rows in a Matrix or higher-dimensional arrays.

Julia provides `map`

for elementwise operations. Is there such a function for pairwise operations? Alternatively, if someone were to implement such a function, where would it be put? It should be so relatively general that it should be close to Base, I think to be really interesting, or perhaps somewhere like Iterators.jl?

Distances.jl has a `pairwise`

function that implements some of this functionality efficiently, but AFAICS not all of it.

Thanks!