koaning / calmcode-feedback

A repo to collect issues with calmcode.io
12 stars 0 forks source link

Better implementation for `Clumper` #181

Closed Sinha-Ujjawal closed 1 year ago

Sinha-Ujjawal commented 1 year ago

I feel like, a better implementation of Clumper would have been the following-

class Clumper:
    def __init__(self, blob):
        self.blob = blob

    # keep function cannot be called without any arguments, atleast 1 would be needed
    def keep(self, func, *funcs):
        return Clumper([d for d in self.blob if all(func(d) for func in (func, *funcs))])

As the list of functions will be relatively small, we only need to filter the blob once checking if the data satisfies all the functions

koaning commented 1 year ago

Wouldn't raising an error be better?

That said, our opinions differ here. A keep(self, *funcs) signature reads more calm to me than your proposal.