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

**URL:** <https://discuss.python.org/t/introduce-funnel-operator-i-e-to-allow-for-generator-pipelines/67701>\
**Category:** Ideas\
**Created:** [October 12, 2024, 11:04pm UTC](https://discuss.python.org/t/introduce-funnel-operator-i-e-to-allow-for-generator-pipelines/67701 "2024-10-12T23:04:08Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![blhsing](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/blhsing/32/25812_2.png) [@blhsing](https://discuss.python.org/u/blhsing)\
**Post date:** [October 23, 2024, 4:01am UTC](https://discuss.python.org/t/introduce-funnel-operator-i-e-to-allow-for-generator-pipelines/67701/28 "2024-10-23T04:01:22Z")

</div>

Here’s a simple implementation of the [syntax](https://discuss.python.org/t/introduce-funnel-operator-i-e-to-allow-for-generator-pipelines/67701/16) I suggested above.

Since in practically all use cases a piped object would be passed as either the first or the second argument I decided to simply use the `>>` operator to denote passing the object as a second argument to avoid specifying the position with a sentinel object:

```python
class pipe:
    def __init__ (self, obj):
        self.obj = obj

    def __or__ (self, func):
        return pipe(func(self.obj))

class using:
    def __init__ (self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs

    def __rlshift__ (self, func):
        return lambda obj: func(obj, *self.args, **self.kwargs)

    def __rrshift__ (self, func):
        first, *rest = self.args
        return lambda obj: func(first, obj, *rest, **self.kwargs)

```

Sample usage:

```python
from itertools import batched

pipe('abcde') | batched << using(2) | map >> using(''.join) | list | print
# outputs ['ab', 'cd', 'e']

```

---

_[View the full topic](https://discuss.python.org/t/introduce-funnel-operator-i-e-to-allow-for-generator-pipelines/67701)._
