Handling of single object vs. 1-element array of object

Note that is_single(1) == is_single([1]) == false, and that this is quite slow. Dispatch on f(x::AbstractArray) vs. f(x) will I think do what you want. Or x isa AbstractArray if you want a test within a function:

julia> @btime is_single(1)
  323.328 ns (3 allocations: 144 bytes)
false

julia> @btime 1 isa AbstractArray
  0.001 ns (0 allocations: 0 bytes)
false
7 Likes