1.1.8.3 Defining a protocol for a sequence

sequenceOf( protocol)
New in version 0.9.1. Return a protocol object that represents a sequence of objects adapted to protocol. Thus, protocols.sequenceOf(IFoo) is a protocol that represents a protocols.IBasicSequence of objects supporting the IFoo protocol. It is guaranteed that you will receive the same protocol object if you call this routine more than once with the same protocol, even across pickling and unpickling of the returned protocol object.

When this function creates a new sequence protocol, it automatically declares an adapter function from protocols.IBasicSequence to the new protocol. The adapter function returns the equivalent of [adapt(x,protocol) for x in sequence], unless one of the adaptations fails, in which case it returns None, causing the adaptation to fail.

The built-in list and tuple types are declared as implementations of protocols.IBasicSequence, so protocols returned by sequenceOf() can be used immediately to convert lists or tuples into lists of objects supporting protocol. If you need to adapt other kinds of sequences using your sequenceProtocol(), you will need to declare that those sequences implement protocols.IBasicSequence unless they subclass tuple, list, or some other type that implements protocols.IBasicSequence.