def transform(item, f):
    """
    Transform an object with a function.  The object will only be transformed
    if it has a transform method.
    """
    if hasattr(item, 'transform'):
        transformed = item.transform(f)
    else:
        transformed = item
    return transformed
