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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,18 @@ R.Min('A', None) # 'A', 'A' < 'None'
- [ ] minBy
- [ ] modify
- [ ] modifyPath
- [ ] modulo
- [x] modulo

Python modulo on negative numbers has different behavior than JS.

```python
5 % -3 # -1
```

```js
5 % -3 // 2
```

- [ ] move
- [x] 0.1.2 multiply
- [ ] nAry
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .match import match
from .Max import Max
from .Min import Min
from .modulo import modulo
from .multiply import multiply
from .Not import Not
from .nth import nth
Expand Down
3 changes: 3 additions & 0 deletions ramda/modulo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .private._curry2 import _curry2

modulo = _curry2(lambda x, y: x % y)
22 changes: 22 additions & 0 deletions test/test_modulo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import unittest

import ramda as R

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


class TestModulo(unittest.TestCase):
def test_divedes_the_first_param_by_the_second_and_returns_the_remainder(self):
self.assertEqual(0, R.modulo(100, 2))
self.assertEqual(1, R.modulo(100, 3))
self.assertEqual(15, R.modulo(100, 17))

def test_preserves_python_style_modulo_evaluation_for_negative_numbers(self):
self.assertEqual(3, R.modulo(-5, 4))


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