Hacker News new | ask | show | jobs
by sampo 1103 days ago

    import pandas as pd
    import functools
    
    (
        pd.Series(range(10))
        .apply(lambda x: x * 10)
        .where(lambda x: x % 2 == 0)
        .pipe(lambda s: functools.reduce(lambda x, y : x + y, s))
    )
1 comments

Readability isn't the best. Also what you present here is method chaining and not functional pipes.
What difference does it make? They're conceptually the same thing. You're mapping immutable data to map/reduce/filter like pure functions to get new data.
Improved code readability. The pipe operator was a game changer for me even after 20 years of programming (I know I was probably touching wrong things).
Is the difference mostly syntactic?
with dot chaining you are restricted to only the functions that the API you're working with provides. With functional pipes you can use whatever functions you want.
In this case, the API provides .pipe, with which you can then use whatever functions you want.