On 30/08/2013 4:17 PM, fp2...@gmail.com wrote:
On Wednesday, August 28, 2013 8:50:53 PM UTC+2, Josh English wrote:
def compose(*funcs):
     for func in funcs:
         if not callable(func):
             raise ValueError('Must pass callable functions')

Imho still, the ValueError you are raising is not that important in this 
context, it would raise an Error anyway.

The main advantage with Josh's approach is that it fails at the point of composition, not when the composed function is first used. It'd be even more useful if it aggregated a list of the failing functions and returned their names as part of the error.

Personally, I'd go with an assertion:

    assert all(map(callable, funcs)), "Must pass callable functions"

I find that it makes it more obvious that this is part of the function contract rather than the actual body.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to