1. Marc Abramowitz
  2. six

Commits

Marc Abramowitz  committed df1019a

Add six.map, which always returns a list, even in PY3.

Using six.map(x) seems nicer than list(map(x))

  • Participants
  • Parent commits a497bee
  • Branches add_map

Comments (0)

Files changed (2)

File six.py

View file
  • Ignore whitespace
         del X
 
 
+def map(f, lst):
+    try:
+        # CPython
+        orig_map = __builtins__['map']
+    except TypeError:
+        # PyPy
+        orig_map = __builtins__.map
+
+    ret = orig_map(f, lst)
+
+    if PY3:
+        ret = list(ret)
+
+    return ret
+
+
 def _add_doc(func, doc):
     """Add documentation to a function."""
     func.__doc__ = doc

File test_six.py

View file
  • Ignore whitespace
 import six
 
 
+def test_six_map():
+    from six import map
+    assert map(lambda x: x * 2, [1, 2, 3]) == [2, 4, 6]
+
+
 def test_add_doc():
     def f():
         """Icky doc"""