Skip to content

Commit

Permalink
Merge pull request #167 from zydmayday/replace
Browse files Browse the repository at this point in the history
add method replace
  • Loading branch information
zydmayday committed Jul 26, 2022
2 parents 107566b + 310ff7f commit 65bc9c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ R.propEq(1, 'v1', {'v1': 1}) # True
- [x] 0.1.2 reject
- [x] 0.2.2 remove
- [x] 0.1.4 repeat
- [ ] replace
- [x] replace
- [x] 0.1.2 reverse
- [ ] scan
- [ ] sequence
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
from .reject import reject
from .remove import remove
from .repeat import repeat
from .replace import replace
from .reverse import reverse
from .slice import slice
from .sort import sort
Expand Down
5 changes: 5 additions & 0 deletions ramda/replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import re

from .private._curry3 import _curry3

replace = _curry3(re.sub)
23 changes: 23 additions & 0 deletions test/test_replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import unittest

import ramda as R

"""
https://github.com/ramda/ramda/blob/master/test/replace.js
"""


class TestReplace(unittest.TestCase):
def test_replaces_substrings_of_the_input_string(self):
self.assertEqual('one two three', R.replace('1', 'one', '1 two three'))

def test_replaces_regex_matches_of_the_input_string(self):
self.assertEqual('num num three', R.replace(r'\d+', 'num', '1 2 three'))

def test_replaces_curry(self):
self.assertEqual('num num three', R.replace(r'\d+')('num')('1 2 three'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 65bc9c1

Please sign in to comment.