pyre.patterns

Package Contents

class pyre.patterns.observable(**kwds)

Provide notification support for classes that maintain dynamic associations with multiple clients.

Observers, i.e. clients of the Observable, register event handlers that will be invoked to notify them whenever something interesting happens to the Observable. The nature of what is being observed is defined by Observable descendants and their managers. For example, instances of pyre.calc.Node are observable by the other nodes whose value depends on them. These dependents are notified of value changes and forced to refresh their value cache.

The event handlers are callables that take the observable instance as their single argument.

interface:
addObserver: registers its callable argument with the list of handlers to invoke removeObserver: remove an event handler from the list of handlers to invoke notifyObservers: invoke the registered handlers in the order in which they were registered
observers
notifyObservers(self, **kwds)

Notify all observers

addObserver(self, callback)

Add {callback} to the set of observers

removeObserver(self, callback)

Remove {callback} from the set of observers

pyre.patterns.mean(iterable)

Compute the mean value of the entries in {iterable}

pyre.patterns.powerset(iterable)

Compute the full power set, i.e. the set of all permutations, of the given iterable. For example:

powerset([1,2,3]) –> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)”

Taken from the python itertools documentation

pyre.patterns.vivify(levels=1, atom=dict)

Builds a nested {defaultdict} with a fixed depth and a specified type at the deepest level.

Adopted from (http://en.wikipedia.org/wiki/Autovivification)

pyre.patterns.newPathHash(**kwds)

Build a hashing functor for name hierarchies

class pyre.patterns.cofunctor(*args, **kwds)

Converts a functor into a coroutine

send(self, value)

Accept a value

throw(self, errorTp, error=None, traceback=None)

Raise an exception

close(self)

Shut things down

__next__(self)

Advance

class pyre.patterns.accumulator(**kwds)

Bases: pyre.patterns.CoFunctor.CoFunctor

A coroutine that accumulates data in a container

throw(self, errorTp, error=None, traceback=None)

Handle exceptions

__call__(self)

Store everything that comes in

class pyre.patterns.printer(format=None, **kwds)

Bases: pyre.patterns.CoFunctor.CoFunctor

A coroutine that sends a textual representation of the values it receives to {stdout}

throw(self, errorTp, error=None, traceback=None)

Handle exceptions

__call__(self)

Store everything that comes in

class pyre.patterns.tee

Bases: pyre.patterns.CoFunctor.CoFunctor, list

A coroutine that accumulates data in a container

throw(self, errorTp, error=None, traceback=None)

Raise an exception

close(self)

Shut things down

__call__(self)

Store everything that comes in

pyre.patterns.coroutine(f)

Decorator that automatically primes a coroutine