jackfirth / pyramda

Python package supporting heavy functional programming through currying. Translation of the Ramda library from javascript to python.
MIT License
126 stars 10 forks source link

Fix `always` #11

Closed peteut closed 8 years ago

peteut commented 8 years ago

always is not compliant w/ ramda spec, this patch should fix it:


---
 pyramda/function/always.py      | 6 ++++--
 pyramda/function/always_test.py | 4 ----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/pyramda/function/always.py b/pyramda/function/always.py
index 6f4000f..2e62e7c 100644
--- a/pyramda/function/always.py
+++ b/pyramda/function/always.py
@@ -2,5 +2,7 @@ from .curry import curry

 @curry
-def always(x, y):
-    return x
+def always(x):
+    def _always(*_, **__):
+        return x
+    return _always
diff --git a/pyramda/function/always_test.py b/pyramda/function/always_test.py
index fbcede6..c5e8a63 100644
--- a/pyramda/function/always_test.py
+++ b/pyramda/function/always_test.py
@@ -2,10 +2,6 @@ from .always import always
 from pyramda.private.asserts import assert_equal

-def always_nocurry_test():
-    assert_equal(always(3, "foo"), 3)
-
-
 def always_curry_test():
     always3 = always(3)
     assert_equal(always3("foo"), 3)
-- 
jackfirth commented 8 years ago

This breaks the property where partial application doesn't affect behavior of curried functions. With this patch, always(a, b) is not equivalent to always(a)(b) which is a property I'd like to preserve for as many functions as possible.

peteut commented 8 years ago

I see, thanks for explanation.