filter func chaining
Drew Schaeffer
drew at oakwoodft.com
Fri Nov 28 13:29:29 EST 2008
I am trying to chain filter functions together so I created these 2 functions.
def AndChain(*filters):
return (lambda asset: reduce((lambda r, f: apply(f, asset) and r), filters))
def OrChain(*filters):
return (lambda asset: reduce((lambda r, f: apply(f, asset) or r), filters))
Where filters are simply functions that take a single argument and return true or false. My intention is to use these functions like this:
f = AndChain(AssetTypeFilter(), CurrencyFilter())
filteredCol = filter(f, col)
I am receiving the following error (where Asset is the type of items in my collection)
Traceback (most recent call last):
File , line 0, in <stdin>##44
File c:\proj\ofts\com.oakwoodft.ofts.compliance\complianceframework\filters\assetfilters.py, line 5, in <lambda
File c:\proj\ofts\com.oakwoodft.ofts.compliance\complianceframework\filters\assetfilters.py, line 5, in <lambda
TypeError: <Asset object at 0x000000000000002B> is not enumerable
Am I going about this totally wrong? Is there a better solution?
Thanks.
Drew Schaeffer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081128/7abe5485/attachment.html>
More information about the Python-list
mailing list