code: def MapFields(function, key=True):
      
      @use_raw_input
      def _MapFields(bag):
          try:
              factory = type(bag)._make
          except AttributeError:
              factory = type(bag)
  
          if callable(key):
              try:
                  fields = bag._fields
              except AttributeError as e:
                  raise UnrecoverableAttributeError(
                      'This transformation works only on objects with named'
                      ' fields (namedtuple, BagType, ...).') from e
  
              return factory(
                  function(value) if key(key_) else value for key_, value in zip(fields, bag)
              )
          elif key:
              return factory(function(value) for value in bag)
          else:
              return NOT_MODIFIED
  
      return _MapFields
docs: Transformation factory that maps `function` on the values of a row.
      It can be applied either to
      1. all columns (`key=True`),
      2. no column (`key=False`), or
      3. a subset of columns by passing a callable, which takes column name and returns `bool`
       (same as the parameter `function` in `filter`).
  
      :param function: callable
      :param key: bool or callable
      :return: callable