On Wed, Mar 16, 2016, at 11:20, Random832 wrote:
> How about:
> 
> from functools import partial, reduce
> from operator import mul
> def rcall(arg, func): return func(arg)
> def fpipe(*args): return reduce(rcall, args)

It occurs to me that this suggests a further refinement: have all
functions (and classes? map and filter seem to be classes.) define
__ror__ as calling the left-hand operand. Then this could be written as
"abcd12345xyz" | pfilter(str.isdigit) | pmap(int) | preduce(mul).

You could also define, say, __mul__ as partial application, so you could
write "abcd12345xyz" | filter*str.isdigit | map*int | reduce*mul.

> pfilter = partial(partial, filter)
> pmap = partial(partial, map)
> preduce = partial(partial, reduce)
> 
> fpipe("abcd12345xyz", pfilter(str.isdigit), pmap(int), preduce(mul))
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to