logo

... method chains: chains



Notes

This is the class that we had before.

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

    def keep(self, func):
        return [d for d in self.blob if func(d)]

This is the class that we have now.

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

    def keep(self, func):
        return Clumper([d for d in self.blob if func(d)])

You'll note that we can now chain commands together.

(Clumper(poke_dict)
  .keep(lambda d: 'Grass' in d['type'])
  .keep(lambda d: d['hp'] < 60)
  .blob)

There's an improvement that we could make now though.

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.