sanctuary-js / sanctuary

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

regexp: add S.replace #693

Closed davidchambers closed 3 years ago

davidchambers commented 3 years ago

Supersedes #686

This pull request adds the following function:

replace :: (Array (Maybe String) -> String) -> RegExp -> String -> String

In https://github.com/sanctuary-js/sanctuary/pull/686#discussion_r466296798, @Avaq made a strong case for naming this more general function replace. @Avaq also noted that the specialized function, replaceWith, is trivially derivable from replace. For this reason I decided not to include replaceWith in this pull request; it could easily be added in the future if replace (K ('...')) proves irksome.

I have opened sanctuary-js/sanctuary-site#90 to provide several examples of replace in use.