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

Source code question #28

Closed pvorona closed 6 years ago

pvorona commented 6 years ago

Hello, I've been browsing through source code trying to understand how the thing works and got question considering following function:

const matches = (subjectToMatch) =>
  function () {
    const functions = Object.keys(arguments).map(key => arguments[key])

    return resolveMatchFunctions(subjectToMatch, functions)
  }

Could you explain why is it using Object.keys / arguments instead of using rest args?

const matches = (subjectToMatch) => (...functions) => 
  resolveMatchFunctions(subjectToMatch, functions)

I cant find any test explaining this thing.

leonardiwagner commented 6 years ago

@pvorona The use of Object.keys instead rest parameters, it was because at written time we was compatible with previous versions of node 6 also. Now there is no reason.

You also changed from function to a lambda () => in your example. I remember we had a reason to maintain function probably due lack of lambda own scope, but honestly I can't remember right now the reason. If we remove this also and tests pass, a PR to update this code is welcomed.

pvorona commented 6 years ago

@leonardiwagner Thanks for very fast reply. Tests are OK https://github.com/z-pattern-matching/z/pull/29