Closed nandotorterolo closed 1 year ago
Hello @nandotorterolo! Gracias for reporting that!
I'd say this is a bug on library rather than a documentation error
Your second example works because you explicitly tell tail =[]
, and the first doesn't because Z is understanding to match tail = undefined
, the problem is in this line: https://github.com/z-pattern-matching/z/blob/master/src/matchArray.js#L20
Comparing last match argument (in that case tail
) with the actual value:
deepEqual(matchArgs[matchArgs.length - 1].value, [])
matchArgs[matchArgs.length - 1].value
will be undefined
instead []
in the second example, that's why this doesn't match.I think we need to swap:
matchArgs[matchArgs.length - 1].value
formatchArgs[matchArgs.length - 1].value || []
Then it works fine! However, doing this breaks a test. We just need to check if that really breaks something, or we just need to update the tests.
I'm busy today, but if until tomorrow if we don't receive any fix for that, I'll try to fix this bug myself, thanks again!
Reamde says
but