4 ms·
I really miss pipes in Python. Maybe in version 4.x?
by dr_kiszonka 2y ago
I really miss pipes in Python. Maybe in version 4.x?
- ralmidani 2y agoIf it doesn’t break backward-compatibility there wouldn’t be a need to release a new major version (which very few people have the stomach for anyway).
- Svetlitski 2y agoYou can implement pipes via operator overloading in Python. Whether or not you should is a different question: class Pipe: __slots__ = ("value",) def __init__(self): self.value = None def __or__(self, x): return x(self.value) def __ror__(self, x): self.value = x return self v = Pipe() def double(x): return x + x def triple(x): return x + x + x pipeline_result = 3 + 7 |v| double |v| triple |v| double normal_result = double(triple(double(3+7))) assert pipeline_result == normal_result