From 54d150d30e3e8f70ee043067c1eb9fc0ea75f5eb Mon Sep 17 00:00:00 2001 From: zyd Date: Fri, 3 Jun 2022 15:31:12 +0900 Subject: [PATCH] add method unary --- README.md | 2 +- ramda/__init__.py | 1 + ramda/unary.py | 4 ++++ test/test_unary.py | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 ramda/unary.py create mode 100644 test/test_unary.py diff --git a/README.md b/README.md index 2ecf16a..1b6a37c 100644 --- a/README.md +++ b/README.md @@ -540,7 +540,7 @@ Partially supported - [ ] tryCatch - [ ] type - [ ] unapply -- [ ] unary +- [x] unary - [ ] uncurryN - [ ] unfold - [x] 0.1.2 union diff --git a/ramda/__init__.py b/ramda/__init__.py index c3e1dde..e1790b4 100644 --- a/ramda/__init__.py +++ b/ramda/__init__.py @@ -96,6 +96,7 @@ from .tap import tap from .times import times from .toString import toString +from .unary import unary from .union import union from .unionWith import unionWith from .uniq import uniq diff --git a/ramda/unary.py b/ramda/unary.py new file mode 100644 index 0000000..a9c03b7 --- /dev/null +++ b/ramda/unary.py @@ -0,0 +1,4 @@ +from .nAry import nAry +from .private._curry1 import _curry1 + +unary = _curry1(lambda fn: nAry(1, fn)) diff --git a/test/test_unary.py b/test/test_unary.py new file mode 100644 index 0000000..21ef5ba --- /dev/null +++ b/test/test_unary.py @@ -0,0 +1,20 @@ + +import unittest + +import ramda as R +from ramda.private._inspect import funcArgsLength + +""" +https://github.com/ramda/ramda/blob/master/test/unary.js +""" + + +class TestUnary(unittest.TestCase): + def test_turns_multiple_argument_function_into_unary_one(self): + fn = R.unary(lambda *args: list(args)) + self.assertEqual(1, funcArgsLength(fn)) + self.assertEqual([1], fn(1, 2, 3)) + + +if __name__ == '__main__': + unittest.main()