Skip to content

Instantly share code, notes, and snippets.

@manuphatak
Last active December 12, 2015 07:03
Show Gist options
  • Save manuphatak/03e3497a64988cb6ebd5 to your computer and use it in GitHub Desktop.
Save manuphatak/03e3497a64988cb6ebd5 to your computer and use it in GitHub Desktop.

Revisions

  1. manuphatak revised this gist Dec 12, 2015. No changes.
  2. manuphatak revised this gist Dec 12, 2015. 1 changed file with 10 additions and 11 deletions.
    21 changes: 10 additions & 11 deletions pipeline.py
    Original file line number Diff line number Diff line change
    @@ -3,22 +3,21 @@
    def pipeline(steps, initial=None):
    def apply(result, step):
    yield from step(result)

    yield from reduce(apply, steps, initial)

    yield from reduce(apply, steps, initial)

    if __name__ == '__main__':
    # BEFORE
    before = notify(write(modify(sanitize(concat(read(FILES))))))

    # or, BEFORE
    step1 = read(FILES)
    step2 = concat(step1)
    step3 = sanitize(step2)
    step4 = modify(step3)
    step5 = write(step4)
    before = notify(step5)

    # 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)
  3. manuphatak revised this gist Dec 12, 2015. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions pipeline.py
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,18 @@ def apply(result, step):
    yield from reduce(apply, steps, initial)

    if __name__ == '__main__':
    # BEFORE
    before = notify(write(modify(sanitize(concat(read(FILES))))))
    # BEFORE
    before = notify(write(modify(sanitize(concat(read(FILES))))))

    # or, BEFORE
    step1 = read(FILES)
    step2 = concat(step1)
    step3 = sanitize(step2)
    step4 = modify(step3)
    step5 = write(step4)
    before = notify(step5)

    # AFTER
    process = read, concat, sanitize, modify, write, notify
    after = pipeline(process, FILES)
    # AFTER
    process = read, concat, sanitize, modify, write, notify
    after = pipeline(process, FILES)

  4. manuphatak revised this gist Dec 12, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pipeline.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    from functools import reduce

    def pipeline(process, initial=None):
    def pipeline(steps, initial=None):
    def apply(result, step):
    yield from step(result)

    yield from reduce(apply, process, initial)
    yield from reduce(apply, steps, initial)

    if __name__ == '__main__':
    # BEFORE
  5. manuphatak created this gist Dec 12, 2015.
    16 changes: 16 additions & 0 deletions pipeline.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    from functools import reduce

    def pipeline(process, initial=None):
    def apply(result, step):
    yield from step(result)

    yield from reduce(apply, process, 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)