MLStyle variadic match ast

Sorry for the late reply.

MLStyle supports your use case:

julia> data = :( a::Foo, b::Bar, c :: Foo, d:: Bar )
:((a::Foo, b::Bar, c::Foo, d::Bar))

@match data begin
   :($([:($a :: $b) for (a, b) in pack]...), ) => pack
end

4-element Vector{Tuple{Any, Any}}:
 (:a, :Foo)
 (:b, :Bar)
 (:c, :Foo)
 (:d, :Bar)

I’d suggest using the Expr pattern because :($(pat...), ) is not-that readable.

julia> @match data begin
          Expr(:tuple, [:($a :: $b) for (a, b) in pack]...) => pack
       end
4-element Vector{Tuple{Any, Any}}:
 (:a, :Foo)
 (:b, :Bar)
 (:c, :Foo)
 (:d, :Bar)
1 Like