Introduce funnel operator i,e '|>' to allow for generator pipelines

Functionality and usage of this looks great!

Implementation, however, I imagine is purely at parser level.

To eliminate strain on parser and make it more modular, I would suggest the following:

class Callable:
    def __rcall__(self, positional_arg):
        return self(arg)

And implement the following at parser level:

function($) -> function
function($, 1) -> partial(function, Placeholder, 1)

Unfortunately, _ can not be used and other symbol would have to be found.


This way:

  1. There is convenience for partial, which doesn’t have to be used in conjunction with new funnel operator
  2. There is a new operator, which follows usual standard of operators with its magic method and this opens it to be used in new innovative ways without being tied to specific application.

Restriction on partial has been merged (see: gh-125028: Prohibit placeholders in partial keywords by dg-pb · Pull Request #126062 · python/cpython · GitHub) which was done exactly to pre-empt such possibility for extending it for keyword arguments. I could extend partial with this if this approach was taken.


The only missing piece of the puzzle would be:

function(*$) -> ?
function(**$) -> ?

I have played with implementing various objects that can do this as well.

So I am sure it is possible to both:

  • (a) Come up with syntax for such
  • (b) Make an appropriate transformation object[s]?

Given partial lives in functools, maybe a new object could be made specifically for this at lower level - the one which isn’t exposed to needing both C and Python versions and other existing predicaments.

I have done some experimentation with indexed placeholders as well. See: Future of `functools.partial`


If you were to take this path, I could help out.

We could polish the concept, identify needed components and I could take up partial-like object implementation / extension while you could cover operator and parser level shorthands.


I am not 100% sure, but my guess is that if this wasn’t a monolithic implementation but rather a neat combination of modular extensions the chance of it being accepted is much higher.