from functools import reduce def pipeline(steps, initial=None): def apply(result, step): yield from step(result) yield from reduce(apply, steps, initial) if __name__ == '__main__': # BEFORE before = notify(write(modify(sanitize(concat(read(FILES)))))) # AFTER process = read, concat, sanitize, modify, write, notify after = pipeline(process, FILES) # alternate, BEFORE opened_files = read(FILES) meaningless_variable_name = concat(opened_files) etc = sanitize(meaningless_variable_name) step4 = modify(etc) step5 = write(step4) before = notify(step5)