3 ms·
I’ve used this in production: def thread_first(current_value, args): for funcargs in args: if isinstance(funcargs, list): func, *rest
by phyrex 6y ago
I’ve used this in production:
def thread_first(current_value, args):
for funcargs in args:
if isinstance(funcargs, list):
func, *restargs = funcargs
else:
func = funcargs
restargs = []
current_value = func(current_value, *restargs)
if current_value is None:
break
return current_value
It’s modelled after clojure’s ‘->’. Your example would be
thread_first(123, [add10, str, print])