Skip to content

Instantly share code, notes, and snippets.

@mcognetta
mcognetta / Dispatch_UnionAll_code.jl
Last active December 13, 2021 16:41
Dispatching on types with the same UnionAll (but you don't know the types beforehand). https://mcognetta.github.io/post/dispatch_unionall
using SimpleTraits, Test
abstract type A{T} end
struct B{T} <: A{T} end
struct C{T} <: A{T} end
abstract type D{T} <: A{T} end
struct E{T} <: D{T} end
struct F{T} <: D{T} end
sameunionall(::Type{X}, ::Type{Y}) where {X<:A, Y<:A} = !isabstracttype(typejoin(X, Y))