File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -18,3 +18,19 @@ def inner(*args):
1818 return lambda arg : inner (* args , arg )
1919
2020 return lambda arg : inner (arg )
21+
22+
23+ # Uncurry a curried function
24+ def uncurry (f : callable ):
25+ def inner (* args ):
26+ value = f
27+
28+ for arg in args :
29+ try :
30+ value = value (arg )
31+ except Exception :
32+ raise Exception ("incorrect amount of arguments provided" )
33+
34+ return value
35+
36+ return inner
Original file line number Diff line number Diff line change 11import pytest
22
3- from ..src .lib import curry
3+ from ..src .lib import curry , uncurry
44
55
66def add_args (* args ):
@@ -33,3 +33,13 @@ def test_unspecified():
3333
3434def test_zero ():
3535 assert curry (add_args , 0 )() == 0
36+
37+
38+ def test_uncurry ():
39+ assert uncurry (curry (add2 ))(1 , 2 ) == 3
40+
41+
42+ def test_uncurry_incorrect ():
43+ with pytest .raises (Exception ) as e :
44+ uncurry (curry (add2 ))(1 , 2 , 3 )
45+ assert e == "incorrect amount of arguments provided"
You can’t perform that action at this time.
0 commit comments