def predicate(fn=None, name=None, **options):
if not name and not callable(fn):<EOL><INDENT>name = fn<EOL>fn = None<EOL><DEDENT>def inner(fn):<EOL><INDENT>if isinstance(fn, Predicate):<EOL><INDENT>return fn<EOL><DEDENT>p = Predicate(fn, name, **options)<EOL>update_wrapper(p, fn)<EOL>return p<EOL><DEDENT>if fn:<EOL><INDENT>return inner(fn)<EOL><DEDENT>else:<EOL><INDENT>return inner<EOL><DEDENT>
Decorator that constructs a ``Predicate`` instance from any function::

    >>> @predicate
    ... def is_book_author(user, book):
    ...     return user == book.author
    ...

    >>> @predicate(bind=True)
    ... def is_book_author(self, user, book):
    ...     if self.context.args:
    ...         return user == book.author