code: def head(records, head):
      
      logging.info('Applying _head generator: '
                   'limiting results to top ' + head + ' records.')
  
      if head == '-0':
          for record in records:
              yield record
      elif '-' in head:
          with _record_buffer(records) as r:
              record_count = sum(1 for record in r())
              end_index = max(record_count + int(head), 0)
              for record in itertools.islice(r(), end_index):
                  yield record
      else:
          for record in itertools.islice(records, int(head)):
              yield record
docs: Limit results to the top N records.
      With the leading `-', print all but the last N records.