Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method minBy #178

Merged
merged 1 commit into from
Aug 26, 2022
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 @@ -512,7 +512,7 @@ we will compare with str(a) and str(b).
R.Min('A', None) # 'A', 'A' < 'None'
```

- [ ] minBy
- [x] minBy
- [ ] modify
- [ ] modifyPath
- [x] 0.1.4 modulo
Expand Down
1 change: 1 addition & 0 deletions ramda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from .mathMod import mathMod
from .Max import Max
from .Min import Min
from .minBy import minBy
from .modulo import modulo
from .multiply import multiply
from .nAry import nAry
Expand Down
10 changes: 10 additions & 0 deletions ramda/minBy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .Min import Min
from .private._curry3 import _curry3


def inner_minBy(f, a, b):
resultB = f(b)
return b if Min(f(a), resultB) == resultB else a


minBy = _curry3(inner_minBy)
18 changes: 18 additions & 0 deletions test/test_minBy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import unittest

import ramda as R

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


class TestMinBy(unittest.TestCase):
def test_returns_the_smaller_value_as_determined_by_the_function(self):
self.assertEqual(2, R.minBy(lambda x: x * x, -3, 2))
self.assertEqual({'x': 3, 'y': 1}, R.minBy(R.prop('x'), {'x': 3, 'y': 1}, {'x': 5, 'y': 10}))


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