sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

match has changed from version 3.1.0 #724

Closed dotnetCarpenter closed 1 year ago

dotnetCarpenter commented 1 year ago

In Sanctuary 3.1.0 the following used to work:

S.compose (S.map (S.prop ("match")))
          (S.match (/[^\-]+(?=\.firefund|\.json$)/i))
          ("39126-borderlesscollective.firefund")
// Just ("borderlesscollective")

But the behavior has changed in commit 0b5611700978861b23bccf3f714771d1b61ffa14.

Now, the following returns Just ([]) and the above throws an error because there is no match property.

S.match (/[^\-]+(?=\.firefund|\.json$)/i)
        ("39126-borderlesscollective.firefund")
// Just ([])

The test is here: https://github.com/sanctuary-js/sanctuary/blob/72bc20ad02c5944b661efdcdd14ab60ceb92c7b3/test/match.js

dotnetCarpenter commented 1 year ago

Looking at the new documentation but still unsure what is the expected return type. ? Is it always suppose to be:

Maybe ([Maybe (String)])
dotnetCarpenter commented 1 year ago

Right, so upon re-reading the new documentation I finally got it!

Takes a pattern and a string, and returns Just an array of captured values if the pattern matches the string; Nothing otherwise.

So the regex MUST contain at least one capture group.