Python any(iterable) and all(iterable) without short-circuiting and with side-effects
<p>I have the following code:</p>

<pre><code>def evAnd(v, *predicates):
    satisfied=True
    for f in predicates:
        if not f(v):
            satisfied=False
            # log: f,v-&gt;False in a map and other side effects
        else:
            # log: f,v-&gt;True in a map and other side effects
    return satisfied


def evOr(v, *predicates):
    satisfied=False
    for f in predicates:
        if f(v):
            satisfied=True
            # log: f,v-&gt;True in a map and other side effects
        else:
            # log: f,v-&gt;False in a map and other side effects
    return satisfied
</code></pre>

<p>What's the Pythonic way to unify the above in a single function? (as there is considerable side-effect code where the log messages are placed) Notice the presence of side effects and the need to evaluate the outcome for <strong>all</strong> predicates without the short-circuiting of <a href="http://docs.python.org/2/library/functions.html#any" rel="nofollow">any</a> and <a href="http://docs.python.org/2/library/functions.html#all" rel="nofollow">all</a></p>

<h2>solution based on accepted answer</h2>

<p>So, here's what I did in the end based on the accepted answer:</p>

<pre><code>def adorn(predicate):
    def rv(v):
        rvi = predicate(v)
        if rvi:
            print "%s is satisfied for value %d" % (predicate.__name__, v)
            # any other side effects
        else:
            print "%s is not satisfied for value %d" % (predicate.__name__, v)
            # any other side effects
        return rvi
    return rv


def my_all(n, predicates):
    return reduce(operator.and_, map( lambda x : x(n), map(adorn, predicates)), True)

def my_any(n, predicates):
    return reduce(operator.or_, map( lambda x : x(n) , map(adorn, predicates)), False)
</code></pre>

<p>It can be tested with:</p>

<pre><code>def even(n):
    return n%2==0

def odd(n):
    return n%2!=0

print my_all(3, [even, odd])
print my_any(4, [even, odd])
</code></pre>
