I would like to understand a line of code similar to that:
df.groupBy(someExpr).agg(somAgg).where(somePredicate)
I don't get it how to chain the methods as that example using Python. I don't want to understand exactly the previous line of the code, just wanna know some name of that to investigate. I tried to replicate something similar, I'm pretty sure that it is not good implementation but I wrote that as an example of how right now I visualize how the code that I wanna get it works under the hood:
class Example:
def __init__(self, *args):
self.list = [arg for arg in args]
def groupBy(self):
self.list = [value for value in self.list if isinstance(value, int)]
return self
def agg(self):
self.list = sum(self.list)
return self
def where(self, elem):
self.list = [value for value in self.list if value == elem]
return self
df = Example("a",1,3,3,5,"C","D")
df.groupBy().where(3).agg().list
My question is how I can to implement in the best way the methods chain? What happens if each method returns a different type of value? How can I do to remove .list
in my line of code here df.groupBy().where(3).agg().list
to this df.groupBy().where(3).agg()
?