Generalize patterns.
Accept rule as parameter.