How to apply decorators to lambdas?
f = anotherdecorator(lambda x: x * 2)
There appear to be two options which give the functionality, but without the clean syntax:
(1) Keep lambda
and ditch the decorator syntax (as posted by dan04):
f = simpledecorator( lambda : print( "Hello World" ) )
(2) Keep the decorator syntax and use a 1 line def
statement instead of lambda:
@simpledecorator
def f(): print ( "Hello World" )
This 2nd form may be preferable if you want to chain decorators:
@simpledecorator
@simpledecorator
def f(): print ( "Hello World" )