Python 2’s apply() Absent in Python 3
They took out apply()
in Python 3 and I'm a little put out. It used to accept a callable as argument 1, [optionally] an argument list as argument 2, and [optionally] an argument dict as argument 3. It'd execute callable(*arglist, **argdict)
and return the return value.
I had a trick where I'd use it as a class decorator on a class whose __init__()
had no required arguments. That instanced the class immediately after definition and updated its name to point to the instance. I used it for singleton classes.
apply()
is a functional programming tool, but it's not in functools
either, it's just gone. Regrettable.
9 February 2023