Open ajfriend opened 9 years ago
Thanks for the feedback! I bet you're not the only one who would use such a function. The preferred way to do this right now is either with compose
(as you showed) or with pipe
and curried map
:
In[10]: list(map(compose(inc, double), range(3)))
Out[10]: [1, 3, 5]
In[11]: from toolz.curried import map
In [12]: list(pipe(range(3), map(double), map(inc)))
Out[12]: [1, 3, 5]
In [13]: list(pipeseq(range(3), double, inc))
Out[13]: [1, 3, 5]
Yeah, I was using the curried map version a lot, and repeating map
so often that, for long lists of functions, I began writing pipe(seq, *map(map,(func1, func2, func3)))
. But that's kind of gross, so I started using something like pipeseq
.
I suggest that we put things like this in the sandbox, watch how they're used, and then either promote or retire them as appropriate in six months.
Cool. I'll make a pull request.
I think this may raise the question whether all functoolz should get an equivalent.
True, but I think pipe
is pretty natural, and (for me, at least) would be the most useful.
Also, what functoolz would need to be extended, other than thread_first
and thread_last
?
I find that I often want to map a sequence of functions over a list of items.
I realize I could do
but it feels more natural to do use something closer to the
pipe
syntax, likewhich could be implemented with either one of the following
I realize that it doesn't make sense to pollute the
toolz
namespace with too many functions. Consider this a vote for this one tho. I'd certainly use it.