DEV Community

Discussion on: Keeping your code clean by sweeping out "if" statements

Collapse
 
_hhandoko profile image
Herdy Handoko • Edited

This pattern looks like a very rudimentary form of pattern matching in FP-oriented languages. I use it a lot for similar reasons you mentioned.

In Scala, for example:

  • Match against deconstructed complex object and its values
  • Match against an interpolated string pattern
  • Match against a regex pattern
  • Compiler-checked exhaustiveness

There's a lot more, probably warrants its own blog post 😁

Collapse
 
tomazfernandes profile image
Tomaz Lemos • Edited

Hi Herdy, you're not the first one to mention Scala as a comparison, but I haven't really tried it yet. I'll be looking forward to this post then!

I've just written a post on a different pattern, if you'd like to take a look and give your two (or more) cents I'd really appreciate!

dev.to/tomazlemos/keeping-your-cod...

Thanks for your feedback!