def merge_adjacent(gen):
 gen = iter(gen)
 last = next(gen)
 for this in gen:
  if (this.merge_key == last.merge_key):
   last.merge(this)
  elif (last < this):
   (yield last)
   last = this
  else:
   raise AssertionError(('Bad order, %s > %s' % (last, this)))
 (yield last)

def merge_adjacent ( gen ) : gen = iter ( gen ) last = next ( gen ) for this in gen : if ( this . merge_key == last . merge_key ) : last . merge ( this ) elif ( last < this ) : ( yield last ) last = this else : raise AssertionError ( ( 'Bad order, %s > %s' % ( last , this ) ) ) ( yield last )
merge adjacent messages that compare equal .