z icon indicating copy to clipboard operation
z copied to clipboard

Support unnamed desctructured parameters

Open pvorona opened this issue 7 years ago • 1 comments

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?

pvorona avatar Nov 26 '17 23:11 pvorona

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.

leonardiwagner avatar Nov 27 '17 15:11 leonardiwagner