Why doesn’t Julia have the switch-case
structure? Is it unnecessary, or is there a better solution?
I suggest Pattern Matching — MLStyle.jl Documentation
julia> @match 10 begin
1 => "wrong!"
2 => "wrong!"
10 => "right!"
end
"right!"
2 Likes
Thank you for introducing me to a very attractive package.
If you’re curious, there’s a lively discussion here: A case/switch statement for Julia · Issue #18285 · JuliaLang/julia · GitHub. TLDR it could be a macro instead of being incorporated into the base syntax, as if-statements can already undergo the optimizations switch statements do. Packages have already made such macros, Match.jl is actually referenced in that issue.
2 Likes
Thanks for guidance!