How to dispatch on a Tuple with unknown length, but elements have same abstract type?

zsoerenm
Mon, 16 Jan 2023 09:12:26 +0000
General Usage

Consider this example:

a = (complex(1,2), complex(1.0, 2.0))

The length of a is not fixed to 2, but could be arbitrary.
Is there a way to dispatch on this?
I tried

a isa NTuple{N, <: Complex} where N

but this is obviously false, because a isn’t a NTuple.
It works with

a = (complex(1.0,2.0), complex(1.0, 2.0))

though.

5 posts - 3 participants