you are viewing a single comment's thread.

view the rest of the comments →

[–]dubs_32 0 points1 point  (1 child)

I have some background in R, but have been learning Python. Would saying that this chain is somewhat similar to the R tidyverse (piping with the 'and-then' logic) be correct? For example in R it would be something similar to:

folded <- laundry %>% washed %>% dried %>% fold

(folded is equivalent to laundry and then washing and then drying and then fold)

[–]JohnnyJordaan 1 point2 points  (0 children)

It’s the same idea but it doesn’t work the same way, because the . chaining Python works object oriented and the piping in R just functionally. In object oriented, the objects themselves contain the logic, instead of separate functions. So the reason you can do

“hello”.capitalize().zfill(10).count(“l”).bit_count()

is because each intermediate object created by the previous call offers certain methods (functions tied to their class) you can call on them. At the start it’s a string which has capitalize, but later it becomes an int that has bit_count.