Conversation
The ‘match’ argument provided by String#replace (when given a function) is often irrelevant. If one does require access to the matched substring as a whole, one can parenthesize the whole pattern to capture it.
|
@kl0tl Thoughts on this one? You reviewed David's prior PR. |
|
I understand your point that "one can parenthesize the whole pattern to capture [the matched substring]", but I think in cases where the user really does need access to the whole match, having to deal with the partiality of getting it from the array of matches might be annoying, so it's not quite a free change. Plus there might be cases where you actually don't have access to the regex, if it's coming from a library or something. |
|
Very good points, @MonoidMusician.
True. There is value in treating the whole match specially for this reason. This highlights the impreciseness of the type we are using to represent captured substrings. Consider the regular expression I am not suggesting that we change the type of the captured substrings;
I considered this in sanctuary-js/sanctuary#685, but the circumstances differ: JavaScript libraries can focus on common use cases because the underlying APIs are always available. What is right for Sanctuary may not be right for PureScript. |
|
I don’t have a strong opinion on this but I don’t think that ignoring the first argument of the replacer function is annoying enough to warrant a breaking change. This would be perhaps more appropriate in an opinionated regex library. |
|
Thank you for considering this change. :) |
Commit message:
This is a breaking change, but I believe it would make
replace'slightly more user-friendly.This proposal was conceived while considering sanctuary-js/sanctuary#685 (as was #126).