-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from zydmayday/minBy
add method minBy
- Loading branch information
Showing
4 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |