def _rewrite(self, term):
        """Apply the rewrite rules in RuleSet to top level of term."""

        for rule, sd in self.iter_matches(term):
            # We use for (...) because it's fast in all cases for getting the
            # first element from the match iterator. As we only want that
            # element, we break here
            term = rule.subs(sd)
            break
        return term
Apply the rewrite rules in RuleSet to top level of term.
src/flash/core/serve/dag/rewrite.py