How to check if all fields of a Tuple are the same

Let’s say you have

julia> t = ([1, 2], ["a", "b"])
([1, 2], ["a", "b"])

julia> typeof(t)

Let’s say I have a function that takes in a tuple of abstract arrays, and I really need the elements in the tuple to be abstract arrays. However the tuple has unknown length, so you can’t just write

julia> t isa Tuple{<:AbstractArray, <:AbstractArray}

Ideally I would write

julia> t isa Tuple{<:AbstractArray...}

But that syntax isn’t supported.

Even if I can’t use dispatch to let Julia know the type of this variable at compile time, it would still be nice to throw an error using run-time information if the argument inputted doesn’t match the contract I want.

Thank you


t isa Tuple && all(t isa AbstractArray for t in t)
1 Like

Assume you actually want to check if all elements are AbtractArray and not “the same”.

t <: Tuple{Vararg{AbstractArray}}