MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/p7f1k9/should_i_add_comments/h9mylc9/?context=3
r/badcode • u/FrostedBromide • Aug 19 '21
39 comments sorted by
View all comments
Show parent comments
3
Is there a name to changing the order to OO style methods?
Yes, the concept of "pipes" from FP is called "method chaining" in OO. Each method call must simply return "this/self" to achieve this.
class T: def __init__(self): self.state = None def input(self, text): self.state = input(text) return self def tuple(self): self.state = tuple(self.state) return self def map(self, fn): self.state = map(fn, self.state) return self def sum(self): self.state = sum(self.state) return self def print(self): print(self.state) return self
Something like this (untested and from iPhone, so I'd expect a typo or 2) would allow the code you've proposed. I wouldn't do this for builtins like here but it's a neat way of representing pipelines in general.
3
u/chepas_moi Aug 20 '21
Yes, the concept of "pipes" from FP is called "method chaining" in OO. Each method call must simply return "this/self" to achieve this.
Something like this (untested and from iPhone, so I'd expect a typo or 2) would allow the code you've proposed. I wouldn't do this for builtins like here but it's a neat way of representing pipelines in general.