Did I find the right examples for you? yes no

All Samples(6)  |  Call(3)  |  Derive(0)  |  Import(3)
Fold each changes and accuumulate result using a function

Args:

    @param db: Database, a database object
    @param fun: function, a callable with arity 2
    @param since: int, sequence where to start the feed

@return: list, last acc returned
(more...)

        def fold(db, fun, acc, since=0):
    """Fold each changes and accuumulate result using a function

    Args:

        @param db: Database, a database object
        @param fun: function, a callable with arity 2
        @param since: int, sequence where to start the feed

    @return: list, last acc returned

    Ex of function:

        fun(change_object,acc):
            return acc

    If the function return "stop", the changes feed will stop.


    """

    if not callable(fun):
        raise TypeError("fun isn't a callable")

    with ChangesStream(db, since=since) as st:
        for c in st:
            acc = fun(c, acc)
    return acc
        


src/j/s/jsonobject-couchdbkit-0.6.5.5/tests/test_changes.py   jsonobject-couchdbkit(Download)
 
from couchdbkit import *
from couchdbkit.changes import ChangesStream, fold, foreach
 
class ClientServerTestCase(unittest.TestCase):
            return acc
 
        changes = fold(self.db, fold_fun, [])
 
        self.assert_(len(changes) == 1)

src/c/o/couchdbkit-0.6.5/tests/test_changes.py   couchdbkit(Download)
 
from couchdbkit import *
from couchdbkit.changes import ChangesStream, fold, foreach
 
class ClientServerTestCase(unittest.TestCase):
            return acc
 
        changes = fold(self.db, fold_fun, [])
 
        self.assert_(len(changes) == 1)

src/c/o/couchdbkit-HEAD/tests/test_changes.py   couchdbkit(Download)
 
from couchdbkit import *
from couchdbkit.changes import ChangesStream, fold, foreach
 
class ClientServerTestCase(unittest.TestCase):
            return acc
 
        changes = fold(self.db, fold_fun, [])
 
        self.assert_(len(changes) == 1)