It’s kind of a poor person’s pattern matching, but it works great and I find it much easier to read than switch blocks. It works especially well in TypeScript if you can strictly define the keys of the object with a union type. Glad to hear it’s more performant, too.
I love this JavaScript pattern. It can also be used with objects and written with a fallback, e.g.:
It’s kind of a poor person’s pattern matching, but it works great and I find it much easier to read than switch blocks. It works especially well in TypeScript if you can strictly define the keys of the object with a union type. Glad to hear it’s more performant, too.
Works quite nicely in Perl also (which famously didn’t have switch blocks for decades, and now… kinda does.)
I use this pattern in clojure to implement processors for advent of code! Clean, consistent, easy to reason about.
Oof. This must also have also affected parsers a lot, since there’s often a big switch in the lexer and another in the parser.
I am curious if they ever did fix the optimization issue in v8.