From 0cbe826da75ec4888b9945d59a3866d8c3964850 Mon Sep 17 00:00:00 2001 From: zyd Date: Tue, 7 Jun 2022 14:25:06 +0900 Subject: [PATCH] add method remove --- README.md | 2 +- ramda/__init__.py | 1 + ramda/remove.py | 3 +++ test/test_remove.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ramda/remove.py create mode 100644 test/test_remove.py diff --git a/README.md b/README.md index af83239..68c4a51 100644 --- a/README.md +++ b/README.md @@ -478,7 +478,7 @@ R.propEq(1, 'v1', {'v1': 1}) # True - [x] 0.1.2 reduceRight - [ ] reduceWhile - [x] 0.1.2 reject -- [ ] remove +- [x] remove - [x] 0.1.4 repeat - [ ] replace - [x] 0.1.2 reverse diff --git a/ramda/__init__.py b/ramda/__init__.py index 434a378..6f486e3 100644 --- a/ramda/__init__.py +++ b/ramda/__init__.py @@ -82,6 +82,7 @@ from .reduced import reduced from .reduceRight import reduceRight from .reject import reject +from .remove import remove from .repeat import repeat from .reverse import reverse from .slice import slice diff --git a/ramda/remove.py b/ramda/remove.py new file mode 100644 index 0000000..e36b102 --- /dev/null +++ b/ramda/remove.py @@ -0,0 +1,3 @@ +from .private._curry3 import _curry3 + +remove = _curry3(lambda start, count, arr: arr[:start] + arr[start + count:]) diff --git a/test/test_remove.py b/test/test_remove.py new file mode 100644 index 0000000..5f09c75 --- /dev/null +++ b/test/test_remove.py @@ -0,0 +1,30 @@ + +import unittest + +import ramda as R + +""" +https://github.com/ramda/ramda/blob/master/test/remove.js +""" + +arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] + + +class TestRemove(unittest.TestCase): + def test_splices_out_a_sub_list_of_the_given_list(self): + self.assertEqual(['a', 'b', 'h', 'i', 'j'], R.remove(2, 5, arr)) + + def test_returns_the_appropriate_sublist_with_start_0(self): + self.assertEqual(['f', 'g', 'h', 'i', 'j'], R.remove(0, 5, arr)) + self.assertEqual(['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], R.remove(0, 1, arr)) + self.assertEqual([], R.remove(0, len(arr), arr)) + + def test_removes_the_end_of_the_list_if_the_count_is_too_large(self): + self.assertEqual(['a', 'b'], R.remove(2, 20, arr)) + + def test_retains_the_entire_list_if_the_start_is_too_large(self): + self.assertEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], R.remove(13, 3, arr)) + + +if __name__ == '__main__': + unittest.main()