See toolz.thread_first()
and toolz.thread_last()
.
It seems to me that they make code strictly worse off. Consider
x = f(x)
x = g(x)
x = h(x)
vs.
x = thread_last(x,
f,
g,
h)
The first example is
- more readable and easily understood,
- not reliant on an external Python library,
- easier to debug, as the multiple statements each have their own line, and
- more verbose, but not by a significant margin.
Even if you wanted to pass x
through, say, a variably-sized list of functions with x = thread_first(x, *funcs)
, this could just be accomplished with regular iteration--which is, again, more verbose, but it's not like this situation comes up all that often anyway.
Why would anyone want to use thread_first()
and thread_last()
? It basically seems like very bad style to me. In principle, implementing a way to pipe a list of arguments through functions could result in speedups via parallelization--but it doesn't seem to me as though this actually happens with these implementations.