It would be useful for the underscore function to be serializable. The two primary use cases would be pickling for storage, but more commonly pickling to execute a function in parallel.
The following doesn't work using pickle or the more powerful dill package:
import pickle
import dill
from fn import _ as X
pickle.dumps(X + 1)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0
dill.dumps(X + 1)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0
f = X + 1
pickle.dumps(f)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0
dill.dumps(f)
# ArityError: getattr((_ + 1), '__getstate__') expected 1 arguments, got 0
dill.loads(dill.dumps(lambda x: x + 1))(1)
#2
My very specific use case is for https://github.com/EntilZha/PyFunctional where you can do this to run a map in parallel:
from functional import pseq
# This doesn't work
pseq.range(4).map(X + 1)
# This works
pseq.range(4).map(lambda x: x + 1)
It would be useful for the underscore function to be serializable. The two primary use cases would be pickling for storage, but more commonly pickling to execute a function in parallel.
The following doesn't work using
pickleor the more powerfuldillpackage:My very specific use case is for https://github.com/EntilZha/PyFunctional where you can do this to run a map in parallel: