Skip to content

Commit

Permalink
Merge pull request #178 from zydmayday/minBy
Browse files Browse the repository at this point in the history
add method minBy
  • Loading branch information
zydmayday committed Aug 26, 2022
2 parents a8fc939 + 2979f28 commit 731893a
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 @@ -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 @@ -80,6 +80,7 @@
from .Max import Max
from .maxBy import maxBy
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()

0 comments on commit 731893a

Please sign in to comment.