Bash-like pipes in Python

Steven D'Aprano steve at pearwood.info
Thu Mar 17 06:58:51 EDT 2016


On Thu, 17 Mar 2016 02:20 am, 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)
> pfilter = partial(partial, filter)
> pmap = partial(partial, map)
> preduce = partial(partial, reduce)
> 
> fpipe("abcd12345xyz", pfilter(str.isdigit), pmap(int), preduce(mul))

Intriguing! Thank you for the suggestion.


-- 
Steven




More information about the Python-list mailing list