Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,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 @@ -98,6 +98,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()