"""
Replacement rules.
"""

class Transform(object):
    """
    Generic transformation rule.
    """
    def __init__(self, transform, filter=lambda x: True):
        self.transform = transform
        self.filter = filter

    def __contains__(self, item):
        return self.filter(item)

    def __getitem__(self, key):
        return self.transform(key)

    def get(self, item, default=None):
        if item in self:
            return self[item]
        else:
            return default

@@ -86,16 +86,1232 @@
 on rule.
+%0A%0A    The Transform object is hybrid function/dictionary that is created%0A    with a %60%60transform%60%60 function and a %60%60filter%60%60. When accessed with%0A    an index Transform()%5Bkey%5D it behaves like a default dictionary (or%0A    function) and when accessed with get() it behaves like a dictionary.%0A%0A    %3E%3E%3E from sympy.core.rules import Transform%0A    %3E%3E%3E from sympy.abc import x%0A%0A    This Transform will return, as a value, one more than the key:%0A%0A    %3E%3E%3E add1 = Transform(lambda x: x + 1)%0A    %3E%3E%3E add1%5B1%5D%0A    2%0A    %3E%3E%3E add1%5Bx%5D%0A    x + 1%0A%0A    By default, all values are considered to be in the dictionary. If a filter%0A    is supplied, it will limit the scope of the application of the transform%0A    when accessing the Transform with the get() method; the filter is ignored%0A    when accessing it via index notation (and in this sense the Transform is%0A    like a function or defaultdict):%0A%0A    %3E%3E%3E add1_odd = Transform(lambda x: x + 1, lambda x: x%252 == 1)%0A    %3E%3E%3E add1_odd%5B2%5D%0A    3%0A    %3E%3E%3E add1_odd.get(2) is None%0A    True%0A    %3E%3E%3E add1_odd.get(2, 0)%0A    0%0A%0A    The filter is also used to answer a query as to whether the Transform%0A    contains a given value or not:%0A%0A    %3E%3E%3E 2 in add1_odd%0A    False%0A    %3E%3E%3E 3 in add1_odd%0A    True
 %0A    %22%22%22
@@ -1307,24 +1307,25 @@
 rue%0A    %22%22%22%0A
+%0A
     def __in
@@ -1606,24 +1606,24 @@
 ault=None):%0A
-
         if i
@@ -1635,16 +1635,39 @@
 n self:%0A
+            print 'yo'%0A
         

add Transform docstring examples