code: def apply_to_field_if_exists(effect, field_name, fn, default):
      
      value = getattr(effect, field_name, None)
      if value is None:
          return default
      else:
          return fn(value)
docs: Apply function to specified field of effect if it is not None,
      otherwise return default.