structintersect.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# courtesy of Mason Protter on the Julia Slack | |
@generated function structintersect(a::NamedTuple{a_names}, b::NamedTuple{b_names}) where {a_names, b_names} | |
names = Tuple(intersect(a_names, b_names)) | |
fields = Expr(:tuple, (:(getproperty(a, $(QuoteNode(name))), getproperty(b, $(QuoteNode(name)))) for name in names)...) | |
quote | |
NamedTuple{$names}($fields) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment