Pipe icon indicating copy to clipboard operation
Pipe copied to clipboard

Recommendations for additional operators and make it more Pipe

Open gvariable opened this issue 1 year ago • 0 comments

Wow, what an incredible project and a fantastic idea! When I first came across this repository, it immediately reminded me of the Rust iterator and its ability to chain multiple methods on an iterator in a lazy manner. It got me thinking about how great it would be to implement some of those operations, just like in Rust iterators. For example:

  1. ... | <Pipe function> | collect(factory) instead of factory(... | <Pipe function>) to PIPE ALL!
  2. Creating more official operators that are both practical and captivating for users. Here are some potential examples:
@Pipe
def step_by(iterable, step):
    "Yield one item out of 'step' in the given iterable."
    for i, item in enumerate(iterable):
        if i % step == 0:
            yield item


@Pipe
def reduce(iterable, predicate):
    "Reduce the given iterable to one element using the given criterion."
    return functools.reduce(predicate, iterable)


@Pipe
def position(iterable, predicate):
    "Get the position of the element in the iterable."
    for i, item in enumerate(iterable):
        if predicate(item):
            return i


@Pipe
def next_chunk(iterable, n):
    ...

# something more

If you consider it to be practical, I would be delighted to contribute.

gvariable avatar Aug 10 '23 08:08 gvariable