Match.jl 有一个Deep Matching with Composite Types功能很好用,但是我不能直接原封不动地删去 using Match 改为 using MLStyle
struct Address
street::String
city::String
zip::String
end
struct Person
firstname::String
lastname::String
address::Address
end
personinfo(person) = @match person begin
Person("Julia", lname, _) => "Found Julia $lname"
Person(fname, "Julia", _) => "$fname Julia was here!"
Person(fname, lname,
Address(_, "Cambridge", zip)) => "$fname $lname lives in zip $zip"
Person(_...) => "Unknown person!"
end