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

Issue with example on the web page #65

Open ashleydavis opened 3 years ago

ashleydavis commented 3 years ago

Thanks for this library, it's really nice.

If found an issue with an example on the web page.

If you run this code, nothing matches, it returns undefined:

matches([1])(
  (a, b,  tail)      => 'Will not match here',
  (a = 2, tail = []) => 'Will not match here',
  (a = 1, tail)      => 'Will match here, tail = []'
)

I would have expected the 3rd case to match.

Did the library change and the docs haven't been updated?

leonardiwagner commented 3 years ago

@ashleydavis only if you pass 1 as argument it would match the last case. [1] is an array of 1 .

Please let me know if that answered your question.

ashleydavis commented 3 years ago

The example above (from your README) implies that the last case will be matched and the value returned will be 'Will match here, tail = []'.

This doesn't happen.

Instead, it returns undefined.

So either your example is wrong or a bug has been introduced in the library which breaks this example.