How to write lazy functions which are chainable, in python? -


I want to write functions like lazy and chainable. What would be the best way to do that I know that in a way, yield must be done instead of return .

I want to know that the way the sqlalchemy function is idle to bring data from DB according to the method of getting lazy.

generator ( work with output change returns As can be seen as "lazy" (and can be seen as itertools.chain ), and any other earrer can also chain what if you mean it "Checkable").

But if "cautious" (and lazy) means you want to call fee (). Fie () Fo (). Fum () and all "hard work" is only in the fum (which comes close to SQLLM), then the generator will not help - but instead you will get the "Promise" design pattern Is needed, where each function / method (actually excluding one work) gives an object that records all the conditions, parameters, and obstacles on the operation, and the use of a D-functioning function will ultimately Doing work Is there.

To give a very simple example, "hard work", remote (host, * * kwargs) . You can prepare it in "Lazy Affordable Clothing":

  class RPC (object): def __init __ (self, host): self._host = host self._kws = {} def Doit (self, ** morekws): Remote remote (auto ._host, ** dict (self ._ques, ** more scan)) DIFT __getattr __ (self, name): Def setKev (value): self._kws [name ] = Value returns Auto Returns Setkw  

Now, RPC (x) .foo ('bar'). Baz ('bap') Doit () call Remote (X, FUE = Bar, Falcon = BAP) (And of course you can save the intermediate steps of the series, you can pass them as arguments Are, etc., as long as call doit ).


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -