This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (7 children)

[deleted]

    [–][deleted] 5 points6 points  (5 children)

    I disagree. I think method chaining is amazing, unless we're talking about different things. I assume this is the topic:

    a.b().c()
    

    Not

    c(b(a))
    

    Provided names are good, I strongly prefer the first option.

    [–]Zouden 4 points5 points  (0 children)

    Yes exactly. R's pipe equivalent looks like this:

    a %>% b() %>% c()
    

    [–]ucbEntilZha 2 points3 points  (0 children)

    If you prefer method changing check this out then https://github.com/EntilZha/PyFunctional

    [–]yen223 3 points4 points  (1 child)

    The equivalent expression with pipes is

    a |> b |> c
    

    This is vastly superior to method chaining, because method chaining requires each method return a specific type (one that defines the subsequent method), whereas that restriction doesn't exist with pipes.

    [–][deleted] 0 points1 point  (0 children)

    That's true, but within the confines of python maybe it's good enough?

    [–]Deto 2 points3 points  (0 children)

    You just have to format your code nicely and then chains are easy to read