All Types Except One

Is there any way to simply that I want a type that includes everything but one? I’d expect a syntax like

Union{Number \ Bool, String}

I saw the answer below, but it seems that the function doesn’t exist anymore

no. that said you can make a function that matches these inputs by defining 1 method for Union{Number, String} and a separate method for Bool

1 Like

Is there any reason for not having this? In the sense of defining types with
a set difference being discouraged?

See also this thread, where I wanted to exclude Bool inputs from Integer:

const ExceptBool = Union{Signed, Unsigned}

1 Like

Or in the general case, where this approach might be overly wordy you could also define a more specific method for the excluded type (although you don’t get a MethodError anymore)

foo(::Integer) = bar()
foo(::Bool) = error()
1 Like

Yes, it could be wordy in the general case, but it is needed only once, e.g. in startup.jl, and then ExceptBool or similar can be used for all relevant methods.

1 Like

Sure, often there are many ways, each with its own distinct set of advantages and limitations.