Instantly share code, notes, and snippets.

Embed
What would you like to do?
What's the best way to write function pipelines in Python?

I agree with Guido, in that I think

[ x * 2 for x in some_list if x < 12 ]

is much easier to read than the equivalent

map(lambda x:x * 2, filter(lambda x:x<12, some_list))

But what if you have several functions? In Haskell,

map (f3 . f2 . f1) some_list

is all right, but in Python I'm tempted to express this as,

result = (f1(x) for x in some_list)
result = (f2(x) for x in result)
result = (f3(x) for x in result)

which is repetitious, verbose, among other flaws.

@yedpodtrzitko

This comment has been minimized.

Show comment
Hide comment
@yedpodtrzitko

yedpodtrzitko Sep 8, 2017

Hi, I stumbled upon this by accident, but maybe you want to check pipetools: https://github.com/0101/pipetools

yedpodtrzitko commented Sep 8, 2017

Hi, I stumbled upon this by accident, but maybe you want to check pipetools: https://github.com/0101/pipetools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment