Fun One Liners

@stevengj posted a nice one liner in How to use minimum and maximum for a Vector{SVector{3}}. The idea is to find the smallest component of the first, second, third … element in a vector of vectors.

A = [rand(3) for i = 1:10]
reduce((x,y) -> min.(x,y), A)

It is fast and works for other types to

A = [Tuple(rand(3)) for i = 1:10]
reduce((x,y) -> min.(x,y), A)
using StaticArrays
A = [SVector{3}(rand(3)) for i = 1:10]
reduce((x,y) -> min.(x,y), A)
2 Likes