[Python-checkins] python/nondist/sandbox/itertools itertools.c,1.12,1.13 libitertools.tex,1.11,1.12 test_itertools.py,1.7,1.8 todo.txt,1.11,1.12

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Mon, 27 Jan 2003 17:05:31 -0800


Update of /cvsroot/python/python/nondist/sandbox/itertools
In directory sc8-pr-cvs1:/tmp/cvs-serv20327

Modified Files:
	itertools.c libitertools.tex test_itertools.py todo.txt 
Log Message:
Adopted Skip's suggestion to have imap(func, *args) accept a None value
for func.  Reduces the conceptual distance from map().



Index: itertools.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/itertools.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** itertools.c	28 Jan 2003 00:19:45 -0000	1.12
--- itertools.c	28 Jan 2003 01:05:28 -0000	1.13
***************
*** 668,671 ****
--- 668,676 ----
  
  	numargs = PyTuple_Size(lz->iters);
+ 	if (lz->func == Py_None) {
+ 		argtuple = PyTuple_New(numargs);
+ 		if (argtuple == NULL)
+ 			return NULL;
+ 	}
  
  	for (i=0 ; i<numargs ; i++) {
***************
*** 675,678 ****
--- 680,685 ----
  		PyTuple_SET_ITEM(argtuple, i, val);
  	}
+ 	if (lz->func == Py_None)
+ 		return argtuple;
  	return PyObject_Call(lz->func, argtuple, NULL);
  }

Index: libitertools.tex
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/libitertools.tex,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** libitertools.tex	28 Jan 2003 00:19:45 -0000	1.11
--- libitertools.tex	28 Jan 2003 01:05:29 -0000	1.12
***************
*** 120,127 ****
  \begin{funcdesc}{imap}{func, *iterables}
    Make an iterator that computes the function using arguments from
!   each of the iterables.  Like \function{map()} except 1) that it returns
!   an iterator instead of a list, 2) that it stops when the shortest
!   iterable is exhausted instead of filling in \code{None} for shorter
!   iterables, and 3) that it does not accept \code{None} for \var{func}.
    Equivalent to:
  
--- 120,128 ----
  \begin{funcdesc}{imap}{func, *iterables}
    Make an iterator that computes the function using arguments from
!   each of the iterables.  If \var{func} is set to \code{None}, then
!   \function{imap()} returns the arguments as a tuple.  Like
!   \function{map()} except that it returns an iterator instead of a
!   list and that it stops when the shortest iterable is exhausted
!   instead of filling in \code{None} for shorter iterables.
    Equivalent to:
  
***************
*** 131,135 ****
           while True:
               args = [i.next() for i in iterables]
!              yield func(*args)
    \end{verbatim}
  \end{funcdesc}
--- 132,139 ----
           while True:
               args = [i.next() for i in iterables]
!              if func is None:
!                  yield tuple(args)
!              else:
!                  yield func(*args)
    \end{verbatim}
  \end{funcdesc}

Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/test_itertools.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_itertools.py	27 Jan 2003 23:33:26 -0000	1.7
--- test_itertools.py	28 Jan 2003 01:05:29 -0000	1.8
***************
*** 37,40 ****
--- 37,42 ----
          self.assertEqual(list(imap(operator.pow, range(3), range(1,7))),
                           [0**1, 1**2, 2**3])
+         self.assertEqual(list(imap(None, 'abc', range(5))),
+                          [('a',0),('b',1),('c',2)])
          self.assertRaises(TypeError, imap)
          self.assertRaises(TypeError, imap, operator.neg)

Index: todo.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/itertools/todo.txt,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** todo.txt	28 Jan 2003 00:19:45 -0000	1.11
--- todo.txt	28 Jan 2003 01:05:29 -0000	1.12
***************
*** 1,4 ****
  Comments from Skip and Jack:
-     func=None in map
      provide in-line motivating examples
      ? add default arg to times()
--- 1,3 ----