Alternative to multi-line lambdas: Assign-anywhere def statements

Yawar Amin yawar.amin at
Sun Jan 25 00:00:43 CET 2015


On Saturday, January 24, 2015 at 3:36:04 PM UTC-5, Devin Jeanpierre
> [...]
> Obviously, nobody will be happy until you can do:
> def call(*a, **kw): return lambda f: f(*a, **kw)
> @call()
> def x, y ():
>     yield 1
>     yield 2
> Actually, maybe not even then.

You're probably right, because someone already _has_ come up with that:

Anyway Chris, to answer your question, the python-blocks repo shows the
'functional decorator style' taken to its logical conclusion, with
decorators for all the various functional building blocks like mapping,
folding, currying, etc.

Incidentally, with a properly-defined decorator 'factory', you could get
a pretty generic decorator for your dispatch example:

    cmd = {}
    dispatch = make_dispatch(cmd)

    def foo(*args): print("You asked to foo.")

    def bar(*args): print("There's no wine in the bar.")

    def cmd2(*args): print("Asdf! Asdf!")

    # Etc.



More information about the Python-list mailing list