(*rules)
return _alternatives
Strategy that makes an AlternativeRule out of multiple possible results.
Strategy that makes an AlternativeRule out of multiple possible results.
Strategy that makes an AlternativeRule out of multiple possible results .
def alternatives(*rules):
    """Strategy that makes an AlternativeRule out of multiple possible results."""
    def _alternatives(integral):
        alts = []
        for rule in rules:
            result = rule(integral)
            if (result and not isinstance(result, DontKnowRule) and
                result != integral and result not in alts):
                alts.append(result)
        if len(alts) == 1:
            return alts[0]
        elif alts:
            doable = [rule for rule in alts if not contains_dont_know(rule)]
            if doable:
                return AlternativeRule(doable, *integral)
            else:
                return AlternativeRule(alts, *integral)
    return _alternatives
def alternatives ( * rules ) : def _alternatives ( integral ) : alts = [ ] for rule in rules : result = rule ( integral ) if ( result and not isinstance ( result , DontKnowRule ) and result != integral and result not in alts ) : alts . append ( result ) if len ( alts ) == 1 : return alts [ 0 ] elif alts : doable = [ rule for rule in alts if not contains_dont_know ( rule ) ] if doable : return AlternativeRule ( doable , * integral ) else : return AlternativeRule ( alts , * integral ) return _alternatives