def reduce(fn, sequences, outputs_info, non_sequences=None, go_backwards=False, mode=None, name=None):
 rval = scan(fn=fn, sequences=sequences, outputs_info=outputs_info, non_sequences=non_sequences, go_backwards=go_backwards, truncate_gradient=(-1), mode=mode, name=name)
 if isinstance(rval[0], (list, tuple)):
  return ([x[(-1)] for x in rval[0]], rval[1])
 else:
  return (rval[0][(-1)], rval[1])

def reduce ( fn , sequences , outputs_info , non_sequences = None , go_backwards = False , mode = None , name = None ) : rval = scan ( fn = fn , sequences = sequences , outputs_info = outputs_info , non_sequences = non_sequences , go_backwards = go_backwards , truncate_gradient = ( - 1 ) , mode = mode , name = name ) if isinstance ( rval [ 0 ] , ( list , tuple ) ) : return ( [ x [ ( - 1 ) ] for x in rval [ 0 ] ] , rval [ 1 ] ) else : return ( rval [ 0 ] [ ( - 1 ) ] , rval [ 1 ] )
similar behaviour as pythons reduce .