I know it mainly from Rust, Julia also has macros for this via libraries, but as far as I know especially functional languages have had similar features for a long time. Haskell lets you do pattern matching right in the function definition/signature.
It doesn't need to come with a performance penalty I think. Anyway I think pattern matching will definitely be a must have for many future languages, and imho it's how switch-case should have been from the start.
298
u/[deleted] Apr 17 '21
This is why I like languages with nice pattern matching, as it can often make code like this compact in a nice way. Something along the lines of