JulienPalard / Pipe

A Python library to use infix notation in Python
MIT License
1.96k stars 113 forks source link

Recommendations for additional operators and make it more Pipe #92

Open gvariable opened 1 year ago

gvariable commented 1 year ago

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.