Reduction can be used for this purpose if you leave a copy of the current element as a result of the reduction function.
def diff_summarize(revisionList, nextRevision): '''helper function (adaptor) for using svn.diff_summarize with reduce''' if revisionList:
EDIT: Yes, but no one said that the result of the function in reduce should be scalar. I changed my example to use a list. Basically, the last element is always the previous version (except the first), with all previous elements being the result of a call to svn.diff_summarize . This way you get a list of results as the final result ...
EDIT2: Yes, the code really was broken. I have a workable dummy here:
>>> def compare(lst, nxt): ... if lst: ... prev = lst.pop() ... lst.append((prev, nxt)) ... lst.append(nxt) ... return lst ... >>> reduce(compare, "abcdefg", []) [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e'), ('e', 'f'), ('f', 'g'), 'g']
This has been verified in the shell, as you can see. You will want to replace (prev, nxt) with a call to lst.append compare to actually add a call summary to svn.diff_summarize .
>>> help(reduce) Help on built-in function reduce in module __builtin__: reduce(...) reduce(function, sequence[, initial]) -> value Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty.