Re:What’s New in ES2019
by Kiro on Tuesday July 30, 2019 @09:26AM
(#20564595)
What's the point of pattern matching? Why not just a switch statement?
[ Parent
| on HN ]
Re:What’s New in ES2019
by halfmatthalfcat on Tuesday July 30, 2019 @09:36AM
(#20564677)
Switch pivots off of one value, pattern matching allows you to match on types, destructured values, conditional execution based on the existence (or lack thereof) of those values or types. It's much more flexible then switch (but arguably more complex).
See Scala[1] or Swifts[2]'s implementations.
[1] https://docs.scala-lang.org/tour/pattern-matching.html
[2] https://docs.swift.org/swift-book/ReferenceManual/Patterns.h...