z-pattern-matching / z

Pattern Matching for Javascript
https://z-pattern-matching.github.io/
Apache License 2.0
1.72k stars 50 forks source link

Support unnamed desctructured parameters #32

Open pvorona opened 6 years ago

pvorona commented 6 years ago

Currently I'm investigating the ability of implementing the following:

match({ a: 1, b: 2 })(
  ({ a = 3, b = 4 }) => 'doesnt match',
  ({ a = 1, ...c }) => 'matches with c = { b: 2 }',
  ({ a, b }, { c, d }) => 'doesnt match',
)

Compare to previous version:

match({ a: 1, b: 2 })(
  (x = { a = 3, b = 4 }) => 'doesnt match',
  (x = { a = 1, ...c }) => 'matches with c = { c: 2 }',
  (x = { a, b }, y = { c, d }) => 'doesnt match',
)

So the unneeded parameter x is removed. I can't find any closed issue addressed this idea. What's your thoughts on this thing?

leonardiwagner commented 6 years ago

It's a very good idea @pvorona , I don't have any point to disagree. It makes the object match even simpler! It'll be like the proposal-pattern-matching Object Patterns.

That task is not very hard, just need to check how js-function-reflector returns the data. I'm just not sure how good it works with ... rest parameters.