View are useful constructions of Python 3. For those who never noticed (like me): for a dictionary d
you can write k = d.keys()
and even if you update d
the variable k
will still be giving you the updated keys. You can write then k1 & k2
and it will always give you d1.keys() & d2.keys()
I want to implement this for my personal todo manager, but I would like to make complex views dynamic, or lazily evaluated. That is, I have some views called so
, post
and priority
and I want to be able to write:
now = so | phone & priority
so that later, when the __repr__(now)
is called, evaluation is performed only at that point.
My first thought was to overload the logical operators so I changed View.__and__
to create a new view that remembers itself being a composite of two subviews and applies &
to them at computation. But there seem to be quite a lot of logical operators, so I'm not sure if I'm doing the right thing.
Is there a standard library class that would help me with that? How can I simplify the process?