66from collections import deque
77from math import cos , sqrt
88
9- from ..it import mapr , rmap , zipr , rzip , \
9+ from ..it import map , mapr , rmap , zipr , rzip , \
1010 map_longest , mapr_longest , rmap_longest , \
1111 zip_longest , zipr_longest , rzip_longest , \
1212 first , second , nth , last , lastn , \
2121 window , chunked , \
2222 within , fixpoint
2323
24- from ..fun import composel , identity
24+ from ..fun import composel , identity , curry
2525from ..gmemo import imemoize , gmemoize
2626from ..mathseq import s
2727from ..misc import Popper , ulp
@@ -31,9 +31,15 @@ def noneadd(a, b):
3131 if all (x is not None for x in (a , b )):
3232 return a + b
3333
34+ # Our map is a thin wrapper that makes it mandatory to provide at least one iterable,
35+ # so we can easily curry it with just the function to be applied.
36+ oneplus = lambda x : 1 + x # noqa: E731
37+ add_one = curry (map , oneplus )
38+ assert tuple (add_one (range (5 ))) == tuple (range (1 , 6 ))
39+
3440 # Adding the missing batteries to the algebra of map and zip.
3541 # Note Python's (and Racket's) map is like Haskell's zipWith, but for n inputs.
36- assert tuple (map (add , (1 , 2 ), (3 , 4 ))) == (4 , 6 ) # builtin
42+ assert tuple (map (add , (1 , 2 ), (3 , 4 ))) == (4 , 6 ) # builtin (or ours, doesn't matter)
3743 assert tuple (mapr (add , (1 , 2 ), (3 , 4 ))) == (6 , 4 )
3844 assert tuple (rmap (add , (1 , 2 ), (3 , 4 ))) == (6 , 4 )
3945 assert tuple (zip ((1 , 2 , 3 ), (4 , 5 , 6 ), (7 , 8 ))) == ((1 , 4 , 7 ), (2 , 5 , 8 )) # builtin
0 commit comments